Skip to main content
Features

Authentication

Better Auth sign-in, two-factor recovery and request-scoped authorization.

Open MarkdownFull AI corpusFeedback

Supported flows

Better Auth handles email/password sign-in, email verification, password resets, optional Google sign-in, passkeys, TOTP two-factor authentication and backup-code recovery. Organization invitations and membership are handled by the organization plugin.

src/routes/api/auth/$.ts forwards requests to Better Auth. The screens are under src/routes/auth.*.tsx; provider and session settings live in config/auth.config.ts and lib/auth.

Email and Google setup

Use a unique BETTER_AUTH_SECRET for each application and set NEXT_PUBLIC_SITE_URL to that application's actual origin. Configure RESEND_API_KEY and EMAIL_FROM for verification, password reset and invitation emails.

For Google, configure GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET, then register this authorized redirect URI in your Google OAuth client:

https://your-domain.com/api/auth/callback/google

Use the complete URL, including the scheme and callback path. Register a separate callback for each deployed origin you use. Changing the application URL without updating Google causes a redirect-URI mismatch.

Two-factor authentication and recovery

TOTP is optional rather than required for every new account. Users who enable it receive backup codes and can regenerate them from Security settings. Two-factor enforcement also covers social and email-link sign-ins for accounts that require it.

The verification screen supports using a different account and restarting an expired challenge. Account switching cancels the pending server-side challenge rather than merely navigating away. Incorrect codes remain retryable; a missing or expired challenge requires signing in again.

Users should store backup codes somewhere safe before relying on two-factor authentication. Admin recovery is a privileged support action, not a public bypass.

Server-side authorization

Dashboard routes load request-scoped session data. Organization routes check membership, and admin routes check the platform role. These UI route guards improve navigation but do not replace authorization inside API handlers, server functions or tRPC procedures.

Pass the current request's headers to getSessionForHeaders and organization helpers from lib/auth/request.ts. Do not keep a user's identity or organization in a module-global variable during SSR.

Sensitive client requests are bound to the account that rendered the page. Preserve that account-scope header when extending the clients; a stale tab should ask the user to reload rather than operate as a different account.

Account and organization ownership

An account cannot be deleted while it is the sole owner of an organization. Transfer ownership or delete the organization first. The same ownership rule prevents a sole owner from leaving an organization and abandoning its remaining members.

See Better Auth's TanStack integration for the framework adapter. The shipped kit adds its own account-scope, recovery and authorization protections around that integration.