Fix router initialization in eventhandler
All checks were successful
continuous-integration/drone/push Build is passing
ci/woodpecker/push/woodpecker Pipeline was successful

useRouter has to be called in setup or returns undefined otherwise.
See https://github.com/vuejs/vue-router/issues/3379
This commit is contained in:
2022-02-21 21:40:36 +00:00
parent 4085868cd7
commit e9d4ed1b3e
2 changed files with 11 additions and 6 deletions

View File

@ -20,12 +20,12 @@ export interface Budget {
export const useSessionStore = defineStore('session', {
state: () => ({
Session: useStorage<Session>('session', null, undefined, { serializer: StorageSerializers.object }),
Session: useStorage<Session | null>('session', null, undefined, { serializer: StorageSerializers.object }),
Budgets: useStorage<Map<string, Budget>>('budgets', new Map<string, Budget>(), undefined, { serializer: StorageSerializers.map }),
}),
getters: {
BudgetsList: (state) => [ ...state.Budgets.values() ],
AuthHeaders: (state) => ({'Authorization': 'Bearer ' + state.Session.Token}),
AuthHeaders: (state) => ({'Authorization': 'Bearer ' + state.Session?.Token}),
LoggedIn: (state) => state.Session != null,
},
actions: {
@ -42,15 +42,18 @@ export const useSessionStore = defineStore('session', {
async login(login: any) {
const response = await POST("/user/login", JSON.stringify(login));
const result = await response.json();
return this.loginSuccess(result);
this.loginSuccess(result);
return result;
},
async register(login : any) {
const response = await POST("/user/register", JSON.stringify(login));
const result = await response.json();
return this.loginSuccess(result);
this.loginSuccess(result);
return result;
},
logout() {
this.$reset()
this.Session = null;
this.Budgets.clear();
},
}
})