Improve login/logout

Extract mutation types to mutation-types.js
This commit is contained in:
2022-01-25 20:30:47 +00:00
parent 6dcf7da861
commit 74c4c7cb02
5 changed files with 35 additions and 15 deletions

View File

@ -1,4 +1,6 @@
<script>
import { LOGIN_SUCCESS } from "../store/mutation-types";
export default {
computed: {
dashboard () {
@ -25,7 +27,8 @@ export default {
.then(x => x.json())
.then(x => {
this.$data.error = ""
this.$store.commit("setToken", x.token);
this.$store.commit(LOGIN_SUCCESS, x);
this.$router.replace("/dashboard");
})
.catch(x => this.$data.error = ["The entered credentials are invalid!"]);

View File

@ -58,7 +58,8 @@ $(document).ready(function () {
</form>
{{end}}-->
<script>
<script>import { LOGIN_SUCCESS } from "../store/mutation-types";
export default {
data() {
return {
@ -76,7 +77,7 @@ export default {
.then(x => x.json())
.then(x => {
this.$data.error = ""
this.$store.commit("setToken", x.token);
this.$store.commit(LOGIN_SUCCESS, x.token);
})
.catch(x => this.$data.error = ["Something went wrong!"]);