refactor: centralize frontend auth query gating

This commit is contained in:
2026-08-25 14:29:41 +03:00
parent fff36f252a
commit 268acdf2e1
24 changed files with 352 additions and 82 deletions
+18
View File
@@ -12,9 +12,27 @@ type AuthHandlers = {
};
let auth: AuthHandlers | null = null;
let hasAuthenticatedSession = false;
const authSessionListeners = new Set<() => void>();
function setAuthenticatedSession(next: boolean) {
if (next === hasAuthenticatedSession) return;
hasAuthenticatedSession = next;
for (const listener of authSessionListeners) listener();
}
export function configureAuthClient(handlers: AuthHandlers | null) {
auth = handlers;
setAuthenticatedSession(Boolean(auth?.accessToken()));
}
export function getAuthenticatedSessionSnapshot() {
return hasAuthenticatedSession;
}
export function subscribeAuthenticatedSession(listener: () => void) {
authSessionListeners.add(listener);
return () => authSessionListeners.delete(listener);
}
async function authenticatedFetch(request: Request): Promise<Response> {