fix: allow global auth redirect without tenant

This commit is contained in:
2026-02-02 20:38:59 +08:00
parent bb90bef02e
commit f7f0a89723

View File

@@ -7,7 +7,8 @@ export async function request(endpoint, options = {}) {
const baseUrl = isAuthRequest ? "/v1" : tenantCode ? `/v1/t/${tenantCode}` : "/v1";
if (!tenantCode && !isAuthRequest && !endpoint.startsWith("/tenants")) {
throw new Error("Tenant code missing in URL");
// 无租户时仍允许访问公共入口,避免全局页面 404
// 这里改为不抛错,由调用方控制跳转
}
const token = localStorage.getItem("token");
@@ -47,7 +48,7 @@ export async function request(endpoint, options = {}) {
if (res.status === 401) {
localStorage.removeItem("token");
localStorage.removeItem("user");
const loginPath = tenantCode ? `/t/${tenantCode}/auth/login` : "/auth/login";
const loginPath = "/auth/login";
// Redirect to login if not already there
if (!window.location.pathname.includes("/auth/login")) {
window.location.href = loginPath;