Skip to content

Commit 1ddfc31

Browse files
committed
fix: getUserinfo is compatible with empty roles data
修复getUserinfo接口数据未携带roles字段时登录失败的问题
1 parent d27633f commit 1ddfc31

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/store/modules/user.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { router } from '/@/router';
1414
import { usePermissionStore } from '/@/store/modules/permission';
1515
import { RouteRecordRaw } from 'vue-router';
1616
import { PAGE_NOT_FOUND_ROUTE } from '/@/router/routes/basic';
17+
import { isArray } from '/@/utils/is';
1718

1819
interface UserState {
1920
userInfo: Nullable<UserInfo>;
@@ -118,10 +119,15 @@ export const useUserStore = defineStore({
118119
},
119120
async getUserInfoAction(): Promise<UserInfo> {
120121
const userInfo = await getUserInfo();
121-
const { roles } = userInfo;
122-
const roleList = roles.map((item) => item.value) as RoleEnum[];
122+
const { roles = [] } = userInfo;
123+
if (isArray(roles)) {
124+
const roleList = roles.map((item) => item.value) as RoleEnum[];
125+
this.setRoleList(roleList);
126+
} else {
127+
userInfo.roles = [];
128+
this.setRoleList([]);
129+
}
123130
this.setUserInfo(userInfo);
124-
this.setRoleList(roleList);
125131
return userInfo;
126132
},
127133
/**

0 commit comments

Comments
 (0)