feat: switch to global auth and tenant route prefix

This commit is contained in:
2026-01-26 18:04:05 +08:00
parent 8addf6f900
commit cde4fb8594
25 changed files with 479 additions and 7196 deletions

View File

@@ -3,10 +3,12 @@ import { getTenantCode } from "./tenant";
export async function request(endpoint, options = {}) {
const tenantCode = getTenantCode();
if (!tenantCode) {
const isAuthRequest = endpoint.startsWith("/auth/");
const baseUrl = isAuthRequest ? "/v1" : tenantCode ? `/v1/t/${tenantCode}` : "/v1";
if (!tenantCode && !isAuthRequest && !endpoint.startsWith("/tenants")) {
throw new Error("Tenant code missing in URL");
}
const baseUrl = `/t/${tenantCode}/v1`;
const token = localStorage.getItem("token");
const headers = {
@@ -45,7 +47,7 @@ export async function request(endpoint, options = {}) {
if (res.status === 401) {
localStorage.removeItem("token");
localStorage.removeItem("user");
const loginPath = `/t/${tenantCode}/auth/login`;
const loginPath = tenantCode ? `/t/${tenantCode}/auth/login` : "/auth/login";
// Redirect to login if not already there
if (!window.location.pathname.includes("/auth/login")) {
window.location.href = loginPath;