グローバル認証状態にpermission情報を追加
This commit is contained in:
@@ -9,6 +9,7 @@ export interface IUserState {
|
|||||||
currentDomain: IDomainInfo;
|
currentDomain: IDomainInfo;
|
||||||
LeftDrawer: boolean;
|
LeftDrawer: boolean;
|
||||||
userId?: string;
|
userId?: string;
|
||||||
|
permissions: 'admin'|'user';
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useAuthStore = defineStore('auth', {
|
export const useAuthStore = defineStore('auth', {
|
||||||
@@ -18,6 +19,7 @@ export const useAuthStore = defineStore('auth', {
|
|||||||
LeftDrawer: false,
|
LeftDrawer: false,
|
||||||
currentDomain: {} as IDomainInfo,
|
currentDomain: {} as IDomainInfo,
|
||||||
userId: '',
|
userId: '',
|
||||||
|
permissions: 'user'
|
||||||
}),
|
}),
|
||||||
getters: {
|
getters: {
|
||||||
toggleLeftDrawer(): boolean {
|
toggleLeftDrawer(): boolean {
|
||||||
@@ -36,7 +38,9 @@ export const useAuthStore = defineStore('auth', {
|
|||||||
const result = await api.post(`api/token`, params);
|
const result = await api.post(`api/token`, params);
|
||||||
console.info(result);
|
console.info(result);
|
||||||
this.token = result.data.access_token;
|
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;
|
api.defaults.headers['Authorization'] = 'Bearer ' + this.token;
|
||||||
this.currentDomain = await this.getCurrentDomain();
|
this.currentDomain = await this.getCurrentDomain();
|
||||||
router.push(this.returnUrl || '/');
|
router.push(this.returnUrl || '/');
|
||||||
|
|||||||
Reference in New Issue
Block a user