feat(web): add lightweight workspace matching existing UI
This commit is contained in:
@@ -7,15 +7,17 @@ const TOKEN_STORAGE_KEY = "sybil_admin_token";
|
||||
export type AuthMode = "open" | "token";
|
||||
|
||||
function readStoredToken() {
|
||||
return localStorage.getItem(TOKEN_STORAGE_KEY)?.trim() || null;
|
||||
try { return localStorage.getItem(TOKEN_STORAGE_KEY)?.trim() || null; }
|
||||
catch { return null; }
|
||||
}
|
||||
|
||||
function persistToken(token: string | null) {
|
||||
if (token) {
|
||||
localStorage.setItem(TOKEN_STORAGE_KEY, token);
|
||||
return;
|
||||
try {
|
||||
if (token) localStorage.setItem(TOKEN_STORAGE_KEY, token);
|
||||
else localStorage.removeItem(TOKEN_STORAGE_KEY);
|
||||
} catch {
|
||||
// Browsers that disable storage can still keep a session in this document.
|
||||
}
|
||||
localStorage.removeItem(TOKEN_STORAGE_KEY);
|
||||
}
|
||||
|
||||
function normalizeAuthError(message: string) {
|
||||
@@ -28,7 +30,7 @@ function normalizeAuthError(message: string) {
|
||||
return message;
|
||||
}
|
||||
|
||||
export function useSessionAuth() {
|
||||
export function useSessionAuth({ backgroundSession = true }: { backgroundSession?: boolean } = {}) {
|
||||
const initialToken = readStoredToken() ?? getConfiguredToken() ?? "";
|
||||
|
||||
const [authTokenInput, setAuthTokenInput] = useState(initialToken);
|
||||
@@ -81,9 +83,9 @@ export function useSessionAuth() {
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!isAuthenticated || authMode !== "token") return;
|
||||
if (!backgroundSession || !isAuthenticated || authMode !== "token") return;
|
||||
return startAgentBrowserSession();
|
||||
}, [isAuthenticated, authMode]);
|
||||
}, [isAuthenticated, authMode, backgroundSession]);
|
||||
|
||||
useEffect(() => {
|
||||
// Signing out in one tab retires the others instead of using a stale token.
|
||||
|
||||
Reference in New Issue
Block a user