From 23fb7553caefbe887bc508894101b55f36c7fea2 Mon Sep 17 00:00:00 2001 From: Christian Cueni Date: Wed, 4 May 2022 15:38:59 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20typing=20=F0=9F=A4=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/router/guards.ts | 6 +++--- client/src/stores/user.ts | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) 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: {