Jobber/orchestrator/src/client/hooks/useBasicAuthNavSession.ts
ilia b72612fd06 Add Basic Auth gate, job owner context, and multi-tenant job isolation.
- Server: auth routes, owner profile on requests/jobs/pipeline, migrations
- Client: BasicAuthAppGate, SSE/API session handling, profile quick switch
- Tests: tracer-links, ghostwriter request-context mock, pipeline coverage
- Env examples for cron and optional basic auth credentials

Made-with: Cursor
2026-04-20 21:34:42 -04:00

39 lines
1.1 KiB
TypeScript

import {
getBasicAuthBasicStatus,
peekBasicAuthSessionCredentials,
} from "@client/api/client";
import { useEffect, useState } from "react";
export type BasicAuthNavSession =
| { kind: "inactive" }
| { kind: "active"; username: string | null };
/** When Basic Auth is on, exposes the username from session storage for nav UI. */
export function useBasicAuthNavSession(): BasicAuthNavSession {
const [state, setState] = useState<BasicAuthNavSession>({ kind: "inactive" });
useEffect(() => {
let cancelled = false;
const run = async () => {
try {
const status = await getBasicAuthBasicStatus();
if (cancelled) return;
if (!status.basicAuthEnabled) {
setState({ kind: "inactive" });
return;
}
const creds = peekBasicAuthSessionCredentials();
setState({ kind: "active", username: creds?.username ?? null });
} catch {
if (!cancelled) setState({ kind: "inactive" });
}
};
void run();
return () => {
cancelled = true;
};
}, []);
return state;
}