diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index 7f7226e6..59d56b22 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -94,29 +94,33 @@ export const useUserStore = defineStore({ // save token this.setToken(token); - // get user info - const userInfo = await this.getUserInfoAction(); - - const sessionTimeout = this.sessionTimeout; - if (sessionTimeout) { - this.setSessionTimeout(false); - } else if (goHome) { - const permissionStore = usePermissionStore(); - if (!permissionStore.isDynamicAddedRoute) { - const routes = await permissionStore.buildRoutesAction(); - routes.forEach((route) => { - router.addRoute(route as unknown as RouteRecordRaw); - }); - router.addRoute(PAGE_NOT_FOUND_ROUTE as unknown as RouteRecordRaw); - permissionStore.setDynamicAddedRoute(true); - } - await router.replace(userInfo.homePath || PageEnum.BASE_HOME); - } - return userInfo; + return this.afterLoginAction(goHome); } catch (error) { return Promise.reject(error); } }, + async afterLoginAction(goHome?: boolean): Promise { + if (!this.getToken) return null; + // get user info + const userInfo = await this.getUserInfoAction(); + + const sessionTimeout = this.sessionTimeout; + if (sessionTimeout) { + this.setSessionTimeout(false); + } else { + const permissionStore = usePermissionStore(); + if (!permissionStore.isDynamicAddedRoute) { + const routes = await permissionStore.buildRoutesAction(); + routes.forEach((route) => { + router.addRoute(route as unknown as RouteRecordRaw); + }); + router.addRoute(PAGE_NOT_FOUND_ROUTE as unknown as RouteRecordRaw); + permissionStore.setDynamicAddedRoute(true); + } + goHome && (await router.replace(userInfo.homePath || PageEnum.BASE_HOME)); + } + return userInfo; + }, async getUserInfoAction(): Promise { const userInfo = await getUserInfo(); const { roles = [] } = userInfo;