Skip to content
All findings

Better Auth 1.7 + Next.js 16, hands-on Dec 2026: first login in 4 min, but an email-code sign-in deletes unverified users' passwords and the rate limit trusts X-Forwarded-For

Published 1 Dec 2026

Better Auth is a library, not a service: no account, card, bot wall or MAU meter, and users sit in your own database. A fresh Next.js 16 app had a signed-in user 4 min 10 s after create-next-app; email+password, email codes and magic links all passed plain headless Playwright. Two defaults matter more. First, a user who signs up with a password (unverified by default) and later signs in once with an email code or magic link loses the password: the next password sign-in returns 401 INVALID_EMAIL_OR_PASSWORD. Second, there is no account lockout, and the production rate limit keys on X-Forwarded-For, which a client can set itself on a bare next start.

| Workload step (2026-12-01, our shared auth workload) | Better Auth result | |---|---| | Fresh app → first signed-in user, docs followed verbatim | 4 min 10 s; 0 blocking doc errors, 3 gaps (below) | | What you write yourself | Sign-up/sign-in/code pages and email sending: 162 lines in 8 files here | | npx auth@latest generate / migrate as printed | Exit 2 in a non-TTY shell; migrate --yes created 4 tables in 1.9 s | | Verification email | Not sent by default; sign-up returns a session with emailVerified: false | | Mail time (local Mailpit catcher, n=3) | 0.10–0.24 s (our SMTP hop only, not comparable with hosted senders) | | Headless Playwright (no stealth) | Sign-up, password, code and link sign-in all passed; no challenge exists unless you add one | | 10 wrong passwords 15 s apart, then the right one | All 401; right one 200. No lockout after 21 failed checks | | Rapid wrong passwords, production build | 429 + x-retry-after: 10 from the 4th; none with a random X-Forwarded-For per request | | Wrong email codes | 3 wrong burn the code: right code → 403 TOO_MANY_ATTEMPTS | | User export | Your DB: scrypt salt:key hex in account.password; no ticket |

Better Auth email OTP / magic link removes the password of an unverified user

With the installation guide's emailAndPassword: { enabled: true } plus the emailOTP plugin, this sequence (better-auth 1.7.29, production build) ends with the right password rejected:

log
sign-up/email                        200sign-in/email (password)             200   account rows: [credential]sign-in/email-otp (emailed code)     200   account rows: []sign-in/email (same password)        401   {"message":"Invalid email or password","code":"INVALID_EMAIL_OR_PASSWORD"}server log: WARN [Better Auth]: User not found

The user row still exists. The cause is revokeUnprovenAccountAccess: when an email proof signs in a user with emailVerified: false, Better Auth deletes all of that user's linked accounts (including the password) and sessions. It is intentional (it stops pre-account takeover, where someone registers your email with their own password first), documented in a callout on the email-OTP and magic-link pages, and present in 1.6.35 and every 1.7.x we checked. Because the default config never verifies email, every password user is "unverified", so an app that offers both methods will hit this. We reproduced it with an email code; the magic-link plugin calls the same function (source and docs).

Fix we tested: verify email at sign-up.

ts
emailAndPassword: { enabled: true, requireEmailVerification: true },plugins: [emailOTP({ sendVerificationOnSignUp: true, overrideDefaultEmailVerification: true, async sendVerificationOTP({ email, otp, type }) { /* send */ } })]

Sign-up then returns token: null and mails a code. A password sign-in before verifying gets 403 EMAIL_NOT_VERIFIED. After verifying, a code sign-in leaves the password working (200).

Better Auth has no lockout, and its rate limit is off in `next dev`

There is no per-account lockout, and in next dev the rate limiter is off (documented), so dev-server tests show neither. In a production build the default rule for /sign-in/email is 3 requests per 10 s per IP. The 4th rapid try returned:

log
429 {"message":"Too many requests. Please try again later."}  x-retry-after: 10

Paced 15 s apart, 10 wrong passwords and then the right one all went through (401 ×10, then 200). The email-OTP plugin adds 3 per 60 s per IP on send, check and sign-in. The window restarts from the last allowed request, so three tries 21 s apart still blocked a fourth 63 s after the first.

Better Auth rate limit and X-Forwarded-For on a self-hosted `next start`

By default Better Auth reads the client IP from X-Forwarded-For. next start passes a client-sent X-Forwarded-For through unchanged and only fills in the socket address when the header is missing (we checked with an echo route). With a different random X-Forwarded-For on each request:

  • 8 rapid wrong passwords all got 401 with no 429, and the right password then got 200;
  • 6 rapid email-code sends delivered 6 emails instead of the limit's 3 per 60 s.

The docs warn that "Clients can send this header themselves". Their setting for direct clients, advanced: { ipAddress: { ipAddressHeaders: [] } }, stopped the spoofing (429 on the 4th try). It also makes every client share one counter: another machine signing in with the right password 1 s later got 429. So a bare next start has no per-client setting that holds up. Put a proxy in front that overwrites the header, then set ipAddressHeaders or trustedProxies to match. We did not test Vercel or Cloudflare, which set the header themselves.

Setup: what the Better Auth Next.js docs leave to you

Followed verbatim (install, .env, lib/auth.ts, migrate, route handler, client, Next 16 proxy.ts), next build passed on Next 16.4.6 defaults with the session read inside <Suspense>. The gaps:

  • The SQLite snippet imports better-sqlite3, but the install step never says to install it.
  • npx auth@latest generate and migrate as printed exit with Can't run these migrations without --yes in non-interactive mode. An agent's shell is non-interactive; the CLI page's CI section gives --yes.
  • The old CLI name still works, but npm prints deprecated @better-auth/cli@1.4.21: Package no longer supported, frozen at 1.4.21 while the library is at 1.7.29.
  • The proxy redirects to /sign-in, and Better Auth ships no UI components, so you write every form and the email sender. The hosted providers we tested (Clerk, Kinde, WorkOS, Supabase Auth) all provide hosted pages or components and a mailer, and Clerk and Kinde also lock accounts after repeated failures. With Better Auth all of that is your code.

npx auth check reported only "Schema check passed against the live database." It did not flag unverified email or the IP header. The MCP server it installs (https://mcp.better-auth.com/mcp) has two tools, search_docs and get_doc.

Exporting Better Auth users: scrypt with a hex-text salt

Export is a query on your own database. account.password is <32-hex salt>:<128-hex key>: scrypt N=16384, r=16, p=1, 64-byte key, NFKC-normalised password. The salt is used as the hex text, not the decoded bytes. Python hashlib.scrypt matched only with salt=salt_hex.encode(). A migration script that hex-decodes the salt will reject every password. Email codes are stored in plain text in verification.value by default (storeOTP: "plain").

Method

Same workload as our Clerk, Kinde, WorkOS and Supabase Auth reviews: fresh create-next-app in an Ubuntu 26.04 VM, better-auth.com's installation and Next.js pages followed verbatim with SQLite, mail via nodemailer to a local Mailpit, plain headless Playwright, and curl against next dev and next build && next start. Vendor account, MAU and production-plan steps don't apply. Evidence: repro/NOTES.md, logs, scripts and app source in repro/.

Outdated if: Better Auth changes revokeUnprovenAccountAccess, the email-verification default, or the default IP source for rate limiting.