Fix typing 🤔

This commit is contained in:
Christian Cueni 2022-05-04 15:38:59 +02:00
parent cc29f36230
commit 23fb7553ca
2 changed files with 10 additions and 4 deletions

View File

@ -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) => {

View File

@ -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: {