Handle LOGIN via action
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
<script>
|
||||
import { LOGIN_SUCCESS, TITLE } from "../store/mutation-types";
|
||||
import { LOGIN, LOGIN_SUCCESS, TITLE } from "../store/mutation-types";
|
||||
|
||||
export default {
|
||||
data() {
|
||||
@ -18,11 +18,9 @@ export default {
|
||||
methods: {
|
||||
formSubmit (e) {
|
||||
e.preventDefault();
|
||||
fetch("/api/v1/user/login", {method: "POST", body: JSON.stringify(this.$data.login)})
|
||||
.then(x => x.json())
|
||||
this.$store.dispatch(LOGIN, this.$data.login)
|
||||
.then(x => {
|
||||
this.$data.error = ""
|
||||
this.$store.commit(LOGIN_SUCCESS, x);
|
||||
this.$data.error = "";
|
||||
this.$router.replace("/dashboard");
|
||||
})
|
||||
.catch(x => this.$data.error = ["The entered credentials are invalid!"]);
|
||||
|
Reference in New Issue
Block a user