Skip to main content
Better Auth provides built-in support for:
  • Email and password
  • Social providers (Google, GitHub, Apple, Discord, and more)
You can also extend these with plugins such as username, magic link, passkey, and email OTP.

Email & password

Enable email and password authentication in your auth instance:
auth.ts

Sign up

Call signUp.email on the client with the user’s details:
sign-up.ts
By default, users are automatically signed in after registration. To disable this:
auth.ts

Sign in

Call signIn.email on the client:
sign-in.ts
Always call client methods from the client side. Do not call them from the server.

Server-side authentication

To authenticate a user from your server, use auth.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

Call signIn.social on the client:
sign-in.ts
You can also authenticate using an idToken or accessToken from the social provider instead of redirecting the user. See the social providers documentation for details.

Sign out

Call signOut on the client:
user-card.tsx
Pass 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 a useSession hook backed by nanostores. It keeps your UI in sync — any change to the session (such as signing out) is reflected immediately.
user.tsx

getSession

If you prefer not to use the hook, call getSession directly:
This works with client-side data-fetching libraries like TanStack Query.

Server side

Pass the incoming request headers to auth.api.getSession:
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 plugins array in your auth instance:
auth.ts
Better Auth will now expose two-factor routes and methods on the server.
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:
auth-client.ts
Two-factor methods are now available on the client:
profile.ts
4

Next steps

See the two-factor plugin documentation for the full list of methods and configuration options.