sonda/web/src/auth/AuthGate.tsx
tgiachi 1c5b4a4fa0 feat(web): API client, session with cross-tab refresh, login screen
- fetch client with bearer token, one retry after a renewal, ApiError with the server code
- session kept in localStorage; renewal is single-flight in a tab and under a Web Lock across tabs, and a tab adopts a session another tab already renewed
- a refused refresh token signs out once; an unreachable server keeps the session
- mediaUrl and onTokenChange for audio and image URLs that carry the token
- sign-in and first-account screen, and a gate that shows the app only when signed in
2026-11-12 11:21:06 +01:00

16 lines
601 B
TypeScript

import type { ReactNode } from 'react'
import { useTranslation } from 'react-i18next'
import LoginPage from './LoginPage'
import { useSession } from './session'
/** Shows the app to a signed-in user and the sign-in form to everyone else. */
export default function AuthGate({ children }: { children: ReactNode }) {
const { status } = useSession()
const { t } = useTranslation()
if (status === 'loading') {
return <div role="status" aria-label={t('common.loading')} className="min-h-screen bg-background" />
}
if (status === 'anonymous') return <LoginPage />
return <>{children}</>
}