グローバル認証状態にpermission情報を追加
This commit is contained in:
@@ -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 || '/');
|
||||
|
||||
Reference in New Issue
Block a user