From 53e5a449d447551049e8915e92c11b14fecb7b76 Mon Sep 17 00:00:00 2001 From: Mouriya Date: Mon, 19 Aug 2024 11:21:24 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=B0=E3=83=AD=E3=83=BC=E3=83=90=E3=83=AB?= =?UTF-8?q?=E8=AA=8D=E8=A8=BC=E7=8A=B6=E6=85=8B=E3=81=ABpermission?= =?UTF-8?q?=E6=83=85=E5=A0=B1=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/stores/useAuthStore.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frontend/src/stores/useAuthStore.ts b/frontend/src/stores/useAuthStore.ts index 16f6ffc..73fe7c3 100644 --- a/frontend/src/stores/useAuthStore.ts +++ b/frontend/src/stores/useAuthStore.ts @@ -9,6 +9,7 @@ export interface IUserState { currentDomain: IDomainInfo; LeftDrawer: boolean; userId?: string; + permissions: 'admin'|'user'; } export const useAuthStore = defineStore('auth', { @@ -18,6 +19,7 @@ export const useAuthStore = defineStore('auth', { LeftDrawer: false, currentDomain: {} as IDomainInfo, userId: '', + permissions: 'user' }), getters: { toggleLeftDrawer(): boolean { @@ -36,7 +38,9 @@ export const useAuthStore = defineStore('auth', { const result = await api.post(`api/token`, params); console.info(result); this.token = result.data.access_token; - this.userId = jwtDecode(result.data.access_token).sub; + const tokenJson = jwtDecode(result.data.access_token) + this.userId = tokenJson.sub; + this.permissions = (tokenJson as any).permissions ?? 'user'; api.defaults.headers['Authorization'] = 'Bearer ' + this.token; this.currentDomain = await this.getCurrentDomain(); router.push(this.returnUrl || '/');