Fix typing 🤔
This commit is contained in:
parent
cc29f36230
commit
23fb7553ca
|
|
@ -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) => {
|
||||
|
|
|
|||
|
|
@ -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: {
|
||||
|
|
|
|||
Loading…
Reference in New Issue