- Email and password
- Social providers (Google, GitHub, Apple, Discord, and more)
Email & password
Enable email and password authentication in your auth instance:auth.ts
Sign up
CallsignUp.email on the client with the user’s details:
sign-up.ts
auth.ts
Sign in
CallsignIn.email on the client:
sign-in.ts
Server-side authentication
To authenticate a user from your server, useauth.api methods directly:
server.ts
If the server cannot return a
Response object, you’ll need to manually parse and set cookies. For Next.js, Better Auth provides a plugin to handle this automatically.Social sign-on
Better Auth supports Google, GitHub, Apple, Discord, and many more social providers. Configure the providers you need on your auth instance:auth.ts
Sign in with a social provider
CallsignIn.social on the client:
sign-in.ts
Sign out
CallsignOut on the client:
user-card.tsx
fetchOptions to redirect on success:
user-card.tsx
Session management
Once a user is signed in, you can access their session data from both the client and server.Client side
useSession hook
Better Auth provides auseSession hook backed by nanostores. It keeps your UI in sync — any change to the session (such as signing out) is reflected immediately.
- React
- Vue
- Svelte
- Solid
- Vanilla
user.tsx
getSession
If you prefer not to use the hook, callgetSession directly:
Server side
Pass the incoming request headers toauth.api.getSession:
- Next.js
- Nuxt
- SvelteKit
- Astro
- Hono
- TanStack Start
server.ts
For more details, see the session management documentation.
Using plugins
One of Better Auth’s key features is its plugin system — you can add complex auth functionality with just a few lines of code. Here’s an example using the two-factor authentication plugin:1
Configure the server
Import the plugin and add it to the Better Auth will now expose two-factor routes and methods on the server.
plugins array in your auth instance:auth.ts
2
Migrate the database
Plugins often require additional tables. Run the CLI to apply the changes:Or apply the migration directly:
To add the schema manually, see the two-factor plugin documentation.
3
Configure the client
Add the matching client plugin to your auth client:Two-factor methods are now available on the client:
auth-client.ts
profile.ts
4
Next steps
See the two-factor plugin documentation for the full list of methods and configuration options.