feat: loginOut
This commit is contained in:
15
src/app.tsx
15
src/app.tsx
@@ -12,11 +12,12 @@ import {
|
||||
SelectLang,
|
||||
} from "@/components";
|
||||
import { getInfo } from "@/services/login";
|
||||
import type { UserVO, TokenType } from "@/services/login/types";
|
||||
import type { UserVO, TokenType, UserInfoVO } from "@/services/login/types";
|
||||
import defaultSettings from "../config/defaultSettings";
|
||||
import { errorConfig } from "./requestErrorConfig";
|
||||
import "@ant-design/v5-patch-for-react-19";
|
||||
import { getAccessToken, getRefreshToken, getTenantId } from "./utils/auth";
|
||||
import { CACHE_KEY, useCache } from "./hooks/web/useCache";
|
||||
|
||||
const isDev = process.env.NODE_ENV === "development";
|
||||
const isDevOrTest = isDev || process.env.CI;
|
||||
@@ -27,10 +28,11 @@ const loginPath = "/user/login";
|
||||
* */
|
||||
export async function getInitialState(): Promise<{
|
||||
settings?: Partial<LayoutSettings>;
|
||||
currentUser?: { user: UserVO };
|
||||
currentUser?: UserInfoVO;
|
||||
loading?: boolean;
|
||||
fetchUserInfo?: () => Promise<{ user: UserVO } | undefined>;
|
||||
fetchUserInfo?: () => Promise<UserInfoVO | undefined>;
|
||||
}> {
|
||||
const { wsCache } = useCache();
|
||||
const fetchUserInfo = async () => {
|
||||
// history.push(loginPath);
|
||||
try {
|
||||
@@ -38,8 +40,10 @@ export async function getInitialState(): Promise<{
|
||||
if (!token) {
|
||||
throw new Error("No token found");
|
||||
}
|
||||
const msg = await getInfo();
|
||||
return msg.data;
|
||||
const { data } = await getInfo();
|
||||
wsCache.set(CACHE_KEY.USER, data);
|
||||
wsCache.set(CACHE_KEY.ROLE_ROUTERS, data.menus);
|
||||
return data;
|
||||
} catch (_error) {
|
||||
history.push(loginPath);
|
||||
}
|
||||
@@ -89,7 +93,6 @@ export const layout: RunTimeLayoutConfig = ({
|
||||
onPageChange: () => {
|
||||
const { location } = history;
|
||||
// 如果没有登录,重定向到 login
|
||||
console.log(initialState);
|
||||
if (!initialState?.currentUser && location.pathname !== loginPath) {
|
||||
history.push(loginPath);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user