feat: switch to global auth and tenant route prefix
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user