import { AuthManager } from '../../AuthManager'; import { AuthProviderSettings } from '../../types'; import { AuthState, Server } from '@plitzi/sdk-shared'; export type UseAuthProps = { server?: Server; isHydrating?: boolean; provider?: string; /** Held stable by the caller: a new object here builds a new provider and re-runs the whole boot decision. */ settings: AuthProviderSettings; }; /** * `loading` is what a space's pages are held back by, so it is deliberately narrow: it means "this page cannot be * rendered yet", not "auth is doing something". A session restored from storage renders immediately and confirms * itself behind the render, which is the difference between a page that appears at once and one that waits on a * round trip to be told what it already knew. */ declare const useAuth: ({ server, isHydrating, provider, settings }: UseAuthProps) => { manager: AuthManager<{ id: number; username: string; email: string; verified: boolean; permissions: string[]; roles: string[]; }>; state: AuthState; /** Who the server rendered this page for, so a consumer can stand on it until the browser has decided. */ bootstrapUser: import('@plitzi/sdk-shared').User | undefined; bootstrapToken: string | undefined; /** * Who this browser can be seen to hold a session for, read synchronously before `init()` runs. * * Published for the same reason `bootstrapUser` is: the provider fills in from an effect, so on a * client-rendered page the auth data source was EMPTY for the first commit — `{{user.*}}` rendered blank and * filled in a moment later, on every reload of every signed-in visitor. */ peekedUser: { id: number; username: string; email: string; verified: boolean; permissions: string[]; roles: string[]; } | undefined; peekedToken: string | undefined; loading: boolean; /** * Before the browser has decided, the server's answer stands. `state` only becomes `authenticated` from * `init()`, which runs in an effect — and effects do not run during a server render, so this read was false on * the server for a visitor the server had just resolved. Page-level access rules are evaluated against it, so * an `accessLevel: 'authenticated'` page never won on the server, and the browser then picked a different page * than the HTML it was hydrating. */ authenticated: boolean; }; export default useAuth;