rename auth token key zino_token -> mahindra_token to avoid cross-app localStorage collision
Point viewService + zino-sdk client at app-specific mahindra_token; drop duplicate zino_token write/remove in useAuth. 401 cleanup now clears mahindra_user. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
208ef22b4e
commit
4fdd3d4b31
@ -1,6 +1,6 @@
|
|||||||
import { APP_ID } from "../config";
|
import { APP_ID } from "../config";
|
||||||
|
|
||||||
const TOKEN_KEY = "zino_token";
|
const TOKEN_KEY = "mahindra_token";
|
||||||
|
|
||||||
function baseUrl(): string {
|
function baseUrl(): string {
|
||||||
return (import.meta.env.VITE_ZINO_API_URL || "").replace(/\/+$/, "");
|
return (import.meta.env.VITE_ZINO_API_URL || "").replace(/\/+$/, "");
|
||||||
@ -21,7 +21,7 @@ async function request<T>(method: string, path: string, body?: unknown): Promise
|
|||||||
});
|
});
|
||||||
if (res.status === 401) {
|
if (res.status === 401) {
|
||||||
localStorage.removeItem(TOKEN_KEY);
|
localStorage.removeItem(TOKEN_KEY);
|
||||||
localStorage.removeItem("zino_user");
|
localStorage.removeItem("mahindra_user");
|
||||||
window.location.href = `${import.meta.env.BASE_URL}login`;
|
window.location.href = `${import.meta.env.BASE_URL}login`;
|
||||||
throw new Error("Unauthorized");
|
throw new Error("Unauthorized");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -56,7 +56,6 @@ export function useAuth() {
|
|||||||
|
|
||||||
localStorage.setItem(TOKEN_KEY, token);
|
localStorage.setItem(TOKEN_KEY, token);
|
||||||
localStorage.setItem(USER_KEY, JSON.stringify(user));
|
localStorage.setItem(USER_KEY, JSON.stringify(user));
|
||||||
localStorage.setItem("zino_token", token);
|
|
||||||
|
|
||||||
setState({ user, token, loading: false, error: null });
|
setState({ user, token, loading: false, error: null });
|
||||||
return { token, user };
|
return { token, user };
|
||||||
@ -72,7 +71,6 @@ export function useAuth() {
|
|||||||
const logout = useCallback(() => {
|
const logout = useCallback(() => {
|
||||||
localStorage.removeItem(TOKEN_KEY);
|
localStorage.removeItem(TOKEN_KEY);
|
||||||
localStorage.removeItem(USER_KEY);
|
localStorage.removeItem(USER_KEY);
|
||||||
localStorage.removeItem("zino_token");
|
|
||||||
setState({ user: null, token: null, loading: false, error: null });
|
setState({ user: null, token: null, loading: false, error: null });
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import type { ApiError, ZinoClientConfig } from "./types";
|
import type { ApiError, ZinoClientConfig } from "./types";
|
||||||
|
|
||||||
const TOKEN_KEY = "zino_token";
|
const TOKEN_KEY = "mahindra_token";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Core HTTP client for the Zino API.
|
* Core HTTP client for the Zino API.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user