Added Pinia account state tracking. Also modified router to go to Start if no account is defined.

This commit is contained in:
Matthew Aaron Raymer
2022-12-02 18:54:47 +08:00
parent 3c388da22d
commit 5c14275a75
4 changed files with 22 additions and 19 deletions

View File

@@ -4,16 +4,19 @@ import { defineStore } from "pinia";
export const useAccountStore = defineStore({
id: "account",
state: () => ({
firstName: "",
lastName: "",
account: JSON.parse(
typeof localStorage["account"] == "undefined"
? null
: localStorage["account"]
),
}),
getters: {
firstName: (state) => state.account.firstName,
lastName: (state) => state.account.lastName,
},
actions: {
reset() {
this.$patch({
firstName: "",
lastName: "",
});
localStorage.removeItem("account");
},
},
});

View File

@@ -1,9 +0,0 @@
import { createStore } from "vuex";
export default createStore({
state: {},
getters: {},
mutations: {},
actions: {},
modules: {},
});