|
|
@@ -4,7 +4,8 @@ import axios, {
|
|
|
type AxiosRequestConfig,
|
|
|
} from "axios";
|
|
|
|
|
|
-import { getApiBaseUrl } from "@/lib/env";
|
|
|
+import { clearUser } from "@/lib/auth-types";
|
|
|
+import { getApiBaseUrl, resolveAuthLoginHref } from "@/lib/env";
|
|
|
|
|
|
/**
|
|
|
* 业务后端接口约定:
|
|
|
@@ -76,7 +77,7 @@ function notifySessionTimeoutAndRedirect() {
|
|
|
if (authTimeoutDialogShown) return;
|
|
|
authTimeoutDialogShown = true;
|
|
|
window.alert("登录超时,请重新登录");
|
|
|
- window.location.assign("/auth/login");
|
|
|
+ window.location.assign(resolveAuthLoginHref());
|
|
|
}
|
|
|
|
|
|
function isPlainObject(v: unknown): v is Record<string, unknown> {
|
|
|
@@ -101,7 +102,10 @@ api.interceptors.response.use(
|
|
|
const body = res.data;
|
|
|
if (!isPlainObject(body) || !("code" in body)) return res;
|
|
|
if (body.code === 600 || body.code === "600") {
|
|
|
- setApiAuthToken(null);
|
|
|
+ if (typeof window !== "undefined") {
|
|
|
+ setApiAuthToken(null);
|
|
|
+ clearUser();
|
|
|
+ }
|
|
|
notifySessionTimeoutAndRedirect();
|
|
|
return Promise.reject(new ApiError("登录状态失效,请重新登录", 600, body));
|
|
|
}
|