UNPKG

@better-auth-ui/core

Version:

Authentication components and data utilities for [Better Auth](https://better-auth.com), available for React and Solid.

61 lines (60 loc) 2.38 kB
/** * Second-factor methods a user can complete the challenge with. * * `totp` and `otp` come from the server's `twoFactorMethods` list. Backup * codes are always available when the server has them enabled, so they are * never part of that list. */ export type TwoFactorMethod = "totp" | "otp"; /** * `sessionStorage` key holding the methods reported by the sign-in response. * * Only the non-sensitive method names are stored — never a code, token, or * the two-factor cookie, which stays HTTP-only. */ export declare const TWO_FACTOR_METHODS_STORAGE_KEY = "better-auth-ui.two-factor-methods"; /** * Sign-in response shape Better Auth returns instead of a session when a * second factor is required. */ export type TwoFactorRedirect = { twoFactorRedirect: true; /** * Left as `unknown` on purpose: the redirect flag is what decides the * navigation, and a malformed method list must never turn into a claim the * caller can trust. {@link parseTwoFactorMethods} does the narrowing. */ twoFactorMethods?: unknown; }; /** * Detect the `twoFactorRedirect` payload in a sign-in response. * * Better Auth deliberately withholds the session until the second factor * succeeds, so every sign-in strategy has to check for this before treating a * successful response as authenticated. * * @param data - Resolved data of a sign-in mutation. */ export declare function isTwoFactorRedirect(data: unknown): data is TwoFactorRedirect; /** * Narrow arbitrary method names to the ones the challenge view can render. * * @param methods - Raw `twoFactorMethods` from the sign-in response. */ export declare function parseTwoFactorMethods(methods?: unknown): TwoFactorMethod[]; /** * Persist the enabled methods so the challenge view knows which options to * offer after the navigation. * * @param methods - Raw `twoFactorMethods` from the sign-in response. */ export declare function storeTwoFactorMethods(methods?: unknown): void; /** * Read the methods stored by the sign-in continuation. * * Returns every method when nothing was stored (e.g. the challenge view was * opened directly) so the user still gets a way in. */ export declare function readTwoFactorMethods(): TwoFactorMethod[]; /** Clear the stored methods once the challenge is finished or abandoned. */ export declare function clearTwoFactorMethods(): void;