UNPKG

@better-auth-ui/core

Version:

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

128 lines (127 loc) 4.66 kB
import { AuthClient } from '../lib/auth-client'; import { AuthLocale } from '../lib/auth-locale'; import { AuthPlugin } from '../lib/auth-plugin'; import { BasePaths } from '../lib/base-paths'; import { DeepPartial } from '../lib/deep-partial'; import { Localization } from '../lib/localization'; import { ViewPaths } from '../lib/view-paths'; import { AdditionalFields } from './additional-fields-config'; import { AvatarConfig } from './avatar-config'; import { EmailAndPasswordConfig } from './email-and-password-config'; import { AuthSocialProvider } from './social-provider-config'; export type SocialSignInMode = "redirect" | "popup"; /** * Core authentication configuration interface. * * Defines the base structure for authentication settings including paths, * providers, navigation functions, and feature flags. */ export interface AuthConfig<TAuthClient extends AuthClient = AuthClient> { /** * The Better Auth client instance used for authentication operations. */ authClient: TAuthClient; /** * Additional user fields rendered on sign-up and the user profile. * @remarks `AdditionalFields` */ additionalFields?: AdditionalFields; /** * Avatar upload, optimization, and deletion configuration. * @remarks `AvatarConfig` * @default { enabled: true, resize: resizeAvatar, size: 256, extension: "png" } */ avatar: AvatarConfig; /** * Base paths for different application sections * @remarks `BasePaths` */ basePaths: BasePaths; /** * Base URL for API endpoints (optional) * @default "" */ baseURL: string; /** * Email and password authentication configuration * @remarks `EmailAndPasswordConfig` */ emailAndPassword: EmailAndPasswordConfig; /** * Localization strings for UI components * @remarks `Localization` */ localization: Localization; /** * Language metadata and translated messages for all auth components. * @remarks `AuthLocale` * @default `defaultAuthLocale` */ locale: AuthLocale; /** * Registered auth plugins. UI packages widen the element type via the * `AuthPluginRegister` module-augmentation slot. * @remarks `AuthPlugin[]` * @default [] */ plugins: AuthPlugin[]; /** * Default redirect path after successful authentication * @default "/" */ redirectTo: string; /** * Allow users to link multiple accounts from the same social provider. * When false, providers already linked to the account are hidden from the available-to-link list. * @default true */ multipleAccountsPerProvider?: boolean; /** * Allow the UI to unlink the final sign-in account. * * Enable this only when Better Auth's * `account.accountLinking.allowUnlinkingAll` option is also enabled. * @default false */ allowUnlinkingAllAccounts?: boolean; /** * List of enabled social authentication providers * Built-in providers can use their string ID. Custom and Generic OAuth * providers use `{ id, label, icon }`. * @remarks `AuthSocialProvider[]` */ socialProviders?: AuthSocialProvider[]; /** * How social sign-in opens the provider flow. * Popup mode requires Better Auth's experimental `oauthPopupClient` action. * @default "redirect" */ socialSignInMode: SocialSignInMode; /** * View path mappings for different authentication views * @remarks `ViewPaths` */ viewPaths: ViewPaths; /** * Function to navigate to a new path * @param options - Navigation options with href and optional replace flag * @default window.location.href = href (or window.location.replace if replace: true) * @example * // TanStack Router * navigate={navigate} * // Next.js * navigate={({href, replace}) => replace ? router.replace(href) : router.push(href)} */ navigate: (options: { to: string; replace?: boolean; }) => void; } export declare const defaultAuthConfig: Omit<AuthConfig, "authClient">; export type AuthConfigOptions<TAuthClient extends AuthClient = AuthClient> = DeepPartial<Omit<AuthConfig<TAuthClient>, "authClient" | "locale">> & { authClient: TAuthClient; /** Imported locale bundle. Defaults to English (`en-US`). */ locale?: AuthLocale; }; /** Resolves defaults, locale messages, plugin messages, and consumer overrides. */ export declare function resolveAuthConfig<TAuthClient extends AuthClient = AuthClient>(options: AuthConfigOptions<TAuthClient>): AuthConfig<TAuthClient>;