Auth fixes for AI-built apps
AI code generators frequently ship auth with OAuth redirect URIs pointing at localhost, signup flows that bypass profile creation, or session tokens stored in localStorage instead of HttpOnly cookies. Industry benchmarks put AI-code vulnerability rates close to half (see our 2026 research) — auth flaws are the plurality of those. This hub groups every sign-in, OAuth, session, and email-delivery fix on the site into one navigable index. Each leaf is a root-cause walkthrough, not a generic auth tutorial.
By Hyder ShahFounder · Afterbuild LabsLast updated 2026-04-18
- 6
- Indexed auth fixes
- ~1/2
- AI code w/ known CVEs
- 60%
- Fixed in provider dashboard
- 100%
- Root-cause fix
What this hub covers
This hub covers authentication and session failures: OAuth callback errors, redirect_uri_mismatch, users unable to log in after deploy, signup buttons that do nothing, password-reset emails that never arrive, and sessions that expire immediately. Providers in scope: Supabase Auth, Clerk, Auth.js (NextAuth), and Google OAuth. The failure modes cut across all four — misconfigured redirect URIs and cookie flags are provider-agnostic.
What this hub does not cover: role-based access control, row-level security in Postgres, Stripe customer object linkage to users, or general 500 errors after deploy. Those live in the database, payments, and deploy hubs respectively. Authorization (what a signed-in user is allowed to do) is the database hub; this hub is authentication (whether the user is signed in at all).
The most common failures
Six auth-category failure modes dominate rescue intakes across Lovable, Bolt, v0, Cursor, Claude Code, Base44, and Replit Agent. Each is a predictable consequence of AI tools optimizing for a localhost demo, not a production domain.
- OAuth redirect URI still on localhost. The AI tool wired Google or GitHub OAuth during scaffolding with
http://localhost:3000/auth/callbackin the Authorized redirect URIs. The production deploy hits Google, Google rejects the callback with Error 400: redirect_uri_mismatch, the user sees an error page. See Google OAuth redirect_uri_mismatch and OAuth callback URL not working in production. - Supabase Site URL left on localhost. Google authenticates the user, redirects to
localhost:3000instead of the production domain, and the session never lands. Supabase Dashboard → Authentication → URL Configuration → Site URL must be the production URL before any real sign-in works. See Users can't log in after deploy. - Signup swallows its own error. Click signup, nothing happens — no network request, no console error. Usually a missing
NEXT_PUBLIC_SUPABASE_ANON_KEYin production, a Supabase client initialized with undefined config, or an RLS policy silently blocking the profile insert. See Signup button does nothing. - Cookie flag mismatch on session.
Secureflag set on a non-HTTPS preview URL drops the cookie.SameSite=Strictrejects the set-cookie on an OAuth callback redirect. JWTexpin milliseconds instead of seconds makes every token look expired. See Session expires immediately after login. - Password reset emails vanish. Supabase default SMTP is shared infrastructure, rate-limited to a handful of emails per hour per project. The founder tests it twice and it works; the first user cohort gets silently dropped. Wire Resend, Postmark, or SendGrid. See Password reset email not sending.
- Tokens stored in localStorage. Not in any single leaf because it is the pattern beneath several — an XSS payload can exfiltrate every active session in one line of JavaScript. Migrate to HttpOnly cookies via Supabase SSR helpers, Clerk middleware, or the Auth.js cookie adapter.
Indexed auth fixes
Each link is a root-cause walkthrough: exact error string, the commit shape that produced it, the fix, and the regression test.
- § FX-07→ READ
OAuth callback URL not working in production
Google or Supabase rejects the callback. Authorized redirect URI still points at localhost or a preview URL.
- § FX-08→ READ
Google OAuth redirect_uri_mismatch
Error 400: redirect_uri_mismatch. The exact production URL must be registered in Authorized redirect URIs — scheme, host, and path.
- § FX-09→ READ
Signup button does nothing
Click, no network request, no error. Swallowed Supabase error, missing NEXT_PUBLIC_ env var, or RLS blocking the profile insert.
- § FX-10→ READ
Users can't log in after deploy
Session cookies missing, JWT secret drift between environments, or Supabase Site URL still set to localhost.
- § FX-11→ READ
Password reset email not sending
Supabase default SMTP is rate-limited. Wire Resend, configure SPF/DKIM/DMARC, stop losing signups to silent bounces.
- § FX-12→ READ
Session expires immediately after login
SameSite=Strict on OAuth, Secure flag over HTTP, or JWT exp written in milliseconds instead of seconds.
Shared root causes
Auth failures cluster around four root causes. Any rescue starts by ruling each out before re-reading the code.
- Config written for localhost. OAuth redirect URIs, Supabase Site URL, Clerk Production Instance, and NEXT_PUBLIC_SITE_URL were set during scaffolding and never updated on the production deploy.
- Env-var scope drift.
NEXT_PUBLIC_SUPABASE_ANON_KEY,NEXTAUTH_SECRET, orCLERK_SECRET_KEYexists in Development but not Production. Every auth call resolves toundefinedand errors get swallowed by try/catch blocks the AI tool wrapped around every request. - Session storage in the wrong place. Tokens in localStorage, sessions without HttpOnly cookies, or a middleware that reads before the set-cookie has returned.
- Concurrency never tested. The generator verified signup once with one user on one tab. Two tabs, two devices, a background session refresh, or an email verification clicked on a different browser — all untested. Race conditions surface at the first ten concurrent users.
Prevention checklist
Merge these before the next auth-related deploy. Each one eliminates a class of silent failure.
- Set Supabase Dashboard → Authentication → URL Configuration → Site URL to the production URL. Add preview URLs to Additional Redirect URLs.
- Add every production and preview callback URL to Google Cloud Console → APIs & Services → Credentials → Authorized redirect URIs.
- Scope
NEXTAUTH_SECRET,CLERK_SECRET_KEY, or the Supabase anon/service keys to every Vercel environment that will serve auth. - Wire a real SMTP provider (Resend, Postmark, SendGrid) and configure SPF, DKIM, and DMARC on the sending domain.
- Move session tokens out of localStorage. Use Supabase SSR cookies, Clerk middleware, or the Auth.js cookie adapter exclusively.
- Set cookies with
HttpOnly,Secure, andSameSite=Lax(notStrictfor OAuth flows). - Write an integration test that signs up a user, verifies the profile row exists, logs out, logs back in, and confirms the session cookie round-trips.
- Test the password-reset flow end-to-end from a non-developer email account on the production domain before launch.
- Log the first 8 characters of auth secrets on boot so a misconfigured deploy is visible in function logs within one request.
- Run the smoke test on two devices in parallel — race conditions only appear under concurrency.
When to bring in a developer
Configuration fixes — OAuth redirect URIs, Site URL, SMTP provider — resolve in 10–30 minutes and do not require a code change. Bring in a developer the moment the failure is any of: session tokens in localStorage, multi-tenant user isolation broken, a password-reset link that logs a different user in, role-based access bypassed via direct Supabase queries, or an audit log that shows one user accessing another user's data.
Escalate immediately for any incident that could constitute unauthorized access or a data breach. Book the Security Audit for a full auth surface review or the Emergency Triage for a single blocking auth incident.
Related clusters
For the stack-wide walkthrough of Supabase Auth specifically, read the Supabase fix stack hub. For builder-specific auth failures, see the per-platform problem pages: Lovable auth not working, Bolt auth not working, Cursor auth not working, v0 auth not working, Replit auth not working, and Lovable OAuth localhost. When the auth symptom chains into another category, continue at the payment fix hub, the deploy fix hub, or the database fix hub.
Users locked out right now?
Book the 48-hour emergency triage for one auth-blocking fix, fixed price, refund if we miss. Or the free diagnostic for a written rescue-vs-rewrite recommendation.