diff --git a/client/src/router/guards.ts b/client/src/router/guards.ts index 7037ac8e..41c23687 100644 --- a/client/src/router/guards.ts +++ b/client/src/router/guards.ts @@ -1,5 +1,5 @@ import type {NavigationGuardWithThis, RouteLocationNormalized} from 'vue-router'; -import { useUserStore } from '@/stores/user' +import {UserState, useUserStore} from '@/stores/user' import type {Store} from 'pinia'; const cookieName = 'loginStatus' @@ -31,11 +31,11 @@ const getCookieValue = (cookieName: string): string => { } // Pina is not ready when router is called the first time by app.use(), so we need to load it here -const getUserStore = (): Store => { +const getUserStore = (): UserState => { if (!userStore) { userStore = useUserStore() } - return userStore + return userStore as unknown as UserState } const loginRequired = (to: RouteLocationNormalized) => { diff --git a/client/src/stores/user.ts b/client/src/stores/user.ts index 1555ee95..7b450ba0 100644 --- a/client/src/stores/user.ts +++ b/client/src/stores/user.ts @@ -1,11 +1,17 @@ import { defineStore } from 'pinia' // typed state https://stackoverflow.com/questions/71012513/when-using-pinia-and-typescript-how-do-you-use-an-action-to-set-the-state + +export type UserState = { + email: string; + loggedIn: boolean; +} + export const useUserStore = defineStore({ id: 'user', state: () => ({ email: '', loggedIn: false - }), + } as UserState), getters: { }, actions: {