diff --git a/{{cookiecutter.project_slug}}/clients/web/vue3/src/stores/user.ts b/{{cookiecutter.project_slug}}/clients/web/vue3/src/stores/user.ts index 3ac0bb819..ba5512d8e 100644 --- a/{{cookiecutter.project_slug}}/clients/web/vue3/src/stores/user.ts +++ b/{{cookiecutter.project_slug}}/clients/web/vue3/src/stores/user.ts @@ -1,5 +1,6 @@ // Pinia Store import { defineStore } from 'pinia' +import { z } from 'zod' import { UserShape } from '@/services/users' const STORAGE_HASH = '{{ random_ascii_string(10) }}' @@ -7,11 +8,13 @@ export const STORAGE_KEY = `{{ cookiecutter.project_slug }}-${STORAGE_HASH}` interface State { user: UserShape | null + token: z.string() | null } export const useUserStore = defineStore('user', { state: (): State => ({ user: null, + token: null, }), persist: { key: STORAGE_KEY, @@ -21,12 +24,16 @@ export const useUserStore = defineStore('user', { return !!state.user }, token: (state) => { - return state.user ? state.user.token : null + return state.token }, }, actions: { updateUser(payload: UserShape) { - this.user = payload + const { token, ...userData } = payload + this.user = userData + if (token) { + this.token = token + } }, clearUser() { this.$reset()