After deploying my Next.js site to Vercel, users kept getting redirected to localhost after logging in. I thought everything was set up correctly - until I found the real issue hidden in my Supabase dashboard.
Karoli Oduor
Software Developer
I recently deployed a Next.js project to Vercel. The app had both email/password and Google authentication using Supabase. Everything ran smoothly in development. But when I pushed it to production, something weird happened.
Users who signed in successfully were redirected to http://localhost:3000
. Not ideal—especially for a live app. At first, I assumed I had messed up my environment variables. So I checked:
NEXTAUTH_URL
– looked good
Vercel environment settings – looked fine
My auth config – nothing unusual
I went through the docs, read GitHub issues, browsed StackOverflow, and even started questioning whether the bug was in NextAuth itself.
Still, no fix.
Two days later, after trying nearly everything, I finally found the culprit: Supabase still had the redirect URL set to localhost:3000
. Here’s what I missed: Supabase uses the Site URL in the Authentication settings to generate OAuth callback URLs. Mine was still set to the local development default.
To fix it, I just needed to:
Go to Supabase
Navigate to Authentication → URL Configuration
Update the Site URL to https://my-production-url.com
Once I hit save, everything started working as expected.
If your production app keeps redirecting to localhost after login, double-check your Supabase Auth redirect settings - not just your code.
Subscribe to our newsletter for more insights and tutorials on software development.
Subscribe Now