import { type LoaderFunctionArgs, type SessionData } from 'react-router'; import type { AuthKitLoaderOptions, AuthorizedData, DataWithResponseInit, Session, UnauthorizedData, UnwrapData } from './interfaces.js'; import type { AuthenticationResponse } from '@workos-inc/node'; export type TypedResponse = Response & { json(): Promise; }; export declare class SessionRefreshError extends Error { /** * Whether the refresh failed for a transient reason (network error, timeout, * 429, or 5xx) rather than a terminal one (the refresh token is dead). When * `true`, the existing session is still valid and should be preserved and * retried rather than destroyed. */ readonly isTransient: boolean; constructor(cause: unknown); } /** * Classifies a refresh failure as transient (retryable) rather than terminal. * Transient failures carry a retryable numeric `status` (408/429/5xx, mirroring * the SDK's own retry set) or are network failures (a "fetch failed" `TypeError`, * possibly wrapped by the SDK with the original `TypeError` as its `cause`). * Anything else (a terminal `invalid_grant` at 400, a 401, or an unrecognized * error) is treated as terminal. */ export declare function isTransientRefreshError(error: unknown): boolean; /** * This function is used to refresh the session by using the refresh token. * It will authenticate the user with the refresh token and return a new session object. * @param request - The request object * @param options - Optional configuration options * @returns A promise that resolves to the new session object */ export declare function refreshSession(request: Request, options?: { organizationId?: string; }): Promise<{ user: import("@workos-inc/node").User; sessionId: string; accessToken: string; organizationId: string | undefined; role: string | undefined; roles: string[] | undefined; permissions: string[] | undefined; entitlements: string[] | undefined; featureFlags: string[] | undefined; impersonator: import("@workos-inc/node").Impersonator | null; sealedSession: any; headers: Record; }>; /** * Saves a WorkOS session to a cookie for use with AuthKit. * * This function is intended for advanced use cases where you need to manually * manage sessions, such as custom authentication flows (email verification, * etc.) that don't use the standard AuthKit authentication flow. * * @param sessionOrResponse The WorkOS session or AuthenticationResponse * containing access token, refresh token, and user information. * @param request A Request object, used to determine cookie settings. * * @example * import { saveSession } from '@workos-inc/authkit-react-router'; * * async function handleEmailVerification(req: Request) { * const { code } = await req.json(); * const authResponse = await workos.userManagement.authenticateWithEmailVerification({ * clientId: process.env.WORKOS_CLIENT_ID, * code, * }); * * await saveSession(authResponse, req); * } */ export declare function saveSession(sessionOrResponse: Session | AuthenticationResponse, request: Request): Promise; export declare function encryptSession(session: Session | AuthenticationResponse): Promise; type LoaderValue = Response | TypedResponse | NonNullable | null; type LoaderReturnValue = Promise> | LoaderValue; type AuthLoader = (args: LoaderFunctionArgs & { auth: AuthorizedData | UnauthorizedData; getAccessToken: () => string | null; }) => LoaderReturnValue; type AuthorizedAuthLoader = (args: LoaderFunctionArgs & { auth: AuthorizedData; getAccessToken: () => string; }) => LoaderReturnValue; /** * This loader handles authentication state, session management, and access token refreshing * automatically, making it easier to build authenticated routes. * * Creates an authentication-aware loader function for React Router. * * @overload * Basic usage with enforced authentication that redirects unauthenticated users to sign in. * * @param loaderArgs - The loader arguments provided by React Router * @param options - Configuration options with enforced sign-in * * @example * export async function loader({ request }: LoaderFunctionArgs) { * return authkitLoader( * { request }, * { ensureSignedIn: true } * ); * } */ export declare function authkitLoader(loaderArgs: LoaderFunctionArgs, options: AuthKitLoaderOptions & { ensureSignedIn: true; }): Promise>; /** * This loader handles authentication state, session management, and access token refreshing * automatically, making it easier to build authenticated routes. * * @overload * Basic usage without enforced authentication, allowing both signed-in and anonymous users. * * @param loaderArgs - The loader arguments provided by React Router * @param options - Optional configuration options * * @example * export async function loader({ request }: LoaderFunctionArgs) { * return authkitLoader({ request }); * } */ export declare function authkitLoader(loaderArgs: LoaderFunctionArgs, options?: AuthKitLoaderOptions): Promise>; /** * This loader handles authentication state, session management, and access token refreshing * automatically, making it easier to build authenticated routes. * * @overload * Custom loader with enforced authentication, providing your own loader function * that will only be called for authenticated users. * * @param loaderArgs - The loader arguments provided by React Router * @param loader - A custom loader function that receives authentication data * @param options - Configuration options with enforced sign-in * * @example * export async function loader({ request }: LoaderFunctionArgs) { * return authkitLoader( * { request }, * async ({ auth }) => { * // This will only be called for authenticated users * const userData = await fetchUserData(auth.accessToken); * return { userData }; * }, * { ensureSignedIn: true } * ); * } */ export declare function authkitLoader(loaderArgs: LoaderFunctionArgs, loader: AuthorizedAuthLoader, options: AuthKitLoaderOptions & { ensureSignedIn: true; }): Promise & AuthorizedData>>; /** * This loader handles authentication state, session management, and access token refreshing * automatically, making it easier to build authenticated routes. * * @overload * Custom loader without enforced authentication, providing your own loader function * that will be called for both authenticated and unauthenticated users. * * @param loaderArgs - The loader arguments provided by React Router * @param loader - A custom loader function that receives authentication data * @param options - Optional configuration options * * @example * export async function loader({ request }: LoaderFunctionArgs) { * return authkitLoader( * { request }, * async ({ auth }) => { * if (auth.user) { * // User is authenticated * const userData = await fetchUserData(auth.accessToken); * return { userData }; * } else { * // User is not authenticated * return { publicData: await fetchPublicData() }; * } * } * ); * } */ export declare function authkitLoader(loaderArgs: LoaderFunctionArgs, loader: AuthLoader, options?: AuthKitLoaderOptions): Promise & (AuthorizedData | UnauthorizedData)>>; export declare function terminateSession(request: Request, { returnTo }?: { returnTo?: string; }): Promise; export declare function getClaimsFromAccessToken(accessToken: string): { iss: string | undefined; exp: number | undefined; sessionId: string; organizationId: string | undefined; role: string | undefined; roles: string[] | undefined; permissions: string[] | undefined; entitlements: string[] | undefined; featureFlags: string[] | undefined; }; export declare function getSessionFromCookie(cookie: string, session?: SessionData): Promise; export {};