What’s Already Built For You
Out of the box, you get:- A polished login page at
/auth - Email/password sign-in and sign-up
- Google OAuth sign-in (optional)
- Magic link sign-in (optional)
- Forgot-password / reset flow
- Session handling and protected routes
- Automatic redirects into your app after login
The key routes to know:
/auth (sign-in page), /auth/reset-password (password reset),
/api/auth/[...all] (Better Auth handler), and /api/auth/callback/google (Google OAuth callback).Getting Started
Run the setup wizard (recommended)
.env.local values for you.Or set your core env vars manually
These three variables are the absolute minimum to get auth working:
Pick your auth methods
With just the core env vars above, email/password auth works immediately. For Google OAuth or magic links, keep reading — you’ll add a few more env vars depending on what you want.
Auth Method Setup
- Email / Password
- Magic Link
- Google OAuth
This is the default and requires zero extra configuration beyond the core env vars above.Your users can sign up with an email and password, and sign in the same way. That’s it — you’re done!
What Happens When a User Signs In
Here’s the flow your users go through:Better Auth handles the session
Better Auth creates or reads the user and session directly in your database.
Verification Checklist
Run through this list to make sure everything is working:Email/password sign-in and sign-up works
Magic link emails arrive (if you enabled magic links)
Password reset emails arrive (if you enabled email auth)
Clicking a magic link or reset link signs you in correctly
Google sign-in works (if you enabled it)
/ loads after sign-in without bouncing back to /authTroubleshooting
I get an error about BETTER_AUTH_SECRET
I get an error about BETTER_AUTH_SECRET
This env var is required. Generate a random string (at least 32 characters) and set it in your
.env.local file. Without it, Better Auth can’t encrypt sessions.Magic link or reset emails aren't arriving
Magic link or reset emails aren't arriving
Double-check that you’ve set
AUTH_EMAIL_FROM and your email provider credentials. If you’re using Loops, make sure you’ve also set the transactional template IDs (LOOPS_AUTH_MAGIC_LINK_TRANSACTIONAL_ID and LOOPS_AUTH_RESET_PASSWORD_TRANSACTIONAL_ID).Google OAuth gives a redirect error
Google OAuth gives a redirect error
The most common cause is a mismatch between your callback URL in Google Cloud and your actual app URL. Make sure your redirect URI is exactly
http://localhost:3000/api/auth/callback/google for local dev (or your production domain equivalent).NEXT_PUBLIC_APP_URL doesn't match my domain
NEXT_PUBLIC_APP_URL doesn't match my domain
This variable must match the domain you’re actually testing on. If you’re running locally, it should be
http://localhost:3000. In production, it should be your live domain with https://.I changed env vars but nothing changed
I changed env vars but nothing changed
You need to restart your dev server after editing
.env.local. Kill the running process and run pnpm dev again.
