import { ReactNode } from 'react'; import { AuthState } from '../components/provider/kc-context.js'; /** * React context for Keycloak authentication state. * Provides auth state to all child components via the `useAuth` hook. */ export declare const AuthReactContext: import('react').Context; /** * Internal bridge component that connects Lit context to React context. * * This component subscribes to the Lit context from `` and * propagates auth state changes to React components via React Context. * * @internal * @component * @param props - Component props * @param props.children - React children to render */ export declare function AuthBridge({ children }: { children: ReactNode; }): import("react/jsx-runtime").JSX.Element; /** * React hook to access Keycloak authentication state. * * This hook provides access to the current authentication state including * the Keycloak instance, authentication status, and any errors. It must be * used within a component tree wrapped by ``. * * @returns {AuthState} Current authentication state * @returns {Keycloak | undefined} returns.keycloak - Keycloak instance (undefined during initialization) * @returns {boolean | undefined} returns.authenticated - Authentication status (true/false/undefined) * @returns {Error | KeycloakError | undefined} returns.error - Authentication error if any * * @example Basic usage * ```tsx * import { useAuth } from 'keycloak-headless/react'; * * function MyComponent() { * const { keycloak, authenticated } = useAuth(); * * if (authenticated) { * return

Welcome, {keycloak?.tokenParsed?.preferred_username}!

; * } * * return

Please log in

; * } * ``` * * @example Accessing token * ```tsx * function UserProfile() { * const { keycloak, authenticated } = useAuth(); * * if (!authenticated || !keycloak) { * return
Not authenticated
; * } * * const token = keycloak.token; * const username = keycloak.tokenParsed?.preferred_username; * const email = keycloak.tokenParsed?.email; * * return ( *
*

{username}

*

{email}

*
* ); * } * ``` * * @example Handling errors * ```tsx * function AuthStatus() { * const { authenticated, error } = useAuth(); * * if (error) { * return
Auth error: {error.message}
; * } * * if (authenticated === undefined) { * return
Checking authentication...
; * } * * return authenticated ?
Logged in
:
Logged out
; * } * ``` * * @example Manual token refresh * ```tsx * function TokenRefreshButton() { * const { keycloak } = useAuth(); * * const handleRefresh = async () => { * try { * const refreshed = await keycloak?.updateToken(30); * console.log('Token refreshed:', refreshed); * } catch (error) { * console.error('Token refresh failed:', error); * } * }; * * return ; * } * ``` */ export declare function useAuth(): AuthState; //# sourceMappingURL=auth-context.d.ts.map