From a9cb85d06046c81a11a300ce58eeae0b65122d99 Mon Sep 17 00:00:00 2001 From: Kloon ImKloon Date: Tue, 12 Sep 2023 11:41:57 +0200 Subject: [PATCH] Fix updateUser (pls do not revert this again) --- frontend/src/stores/auth.ts | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/frontend/src/stores/auth.ts b/frontend/src/stores/auth.ts index 940c0d18..f157afe7 100644 --- a/frontend/src/stores/auth.ts +++ b/frontend/src/stores/auth.ts @@ -18,24 +18,29 @@ export const useAuthStore = defineStore("auth", { }, actions: { // no context as first argument, use `this` instead - setUser(value: IUser) { - if (value === null) { + setUser(user: IUser) { + if (user === null) { this.user = null; return; } - const locale = value.locale || detectLocale(); + const locale = user.locale || detectLocale(); dayjs.locale(locale); - // according to doc u only need .value if legacy: false - // in createI18n but they lied + // according to doc u only need .value if legacy: false but they lied // https://vue-i18n.intlify.dev/guide/essentials/scope.html#local-scope-1 //@ts-ignore - i18n.global.locale = locale; - this.user = value; + i18n.global.locale.value = locale; + this.user = user; }, - updateUser(value: IUser) { - if (typeof value !== "object" || !value) return; - this.setUser(cloneDeep(value)); + updateUser(user: Partial) { + if (user.locale) { + dayjs.locale(user.locale); + // see above + //@ts-ignore + i18n.global.locale.value = user.locale; + } + + this.user = { ...this.user, ...cloneDeep(user) } as IUser; }, // easily reset state using `$reset` clearUser() {