Skip to content

fix(auth): pin OAuth state + sessions to DB regardless of Redis#85

Merged
f-amine merged 1 commit into
masterfrom
fix/auth-state-in-db
May 15, 2026
Merged

fix(auth): pin OAuth state + sessions to DB regardless of Redis#85
f-amine merged 1 commit into
masterfrom
fix/auth-state-in-db

Conversation

@f-amine
Copy link
Copy Markdown
Owner

@f-amine f-amine commented May 15, 2026

Better Auth routes OAuth verification + sessions through secondaryStorage by default when one is configured. Redis hiccup = OAuth callback fails with "State mismatch: verification not found".

  • verification.storeInDatabase: true — OAuth state, magic-link tokens, email-verify tokens land in Postgres
  • session.storeSessionInDatabase: true — sessions in Postgres

Redis remains the rate-limit counter backend (original intent of #34). Rate-limit is best-effort cache; OAuth state is not.

When secondaryStorage is configured Better Auth routes verification
(OAuth state, magic-link tokens, email-verify tokens) and sessions
through it by default. When Redis hiccups — even briefly — those
disappear and OAuth callbacks fail with 'State mismatch: verification
not found'.

Pin both to the DB:
- verification.storeInDatabase: true
- session.storeSessionInDatabase: true

Redis remains the secondaryStorage backend for rate-limit counters
(rateLimit.storage = 'secondary-storage'), which is the original
intent of #34. Rate-limit is best-effort cache, OAuth state is not.
@f-amine f-amine merged commit fee94a6 into master May 15, 2026
2 checks passed
@f-amine f-amine deleted the fix/auth-state-in-db branch May 15, 2026 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant