Supabase login redirects to localhost (or the preview URL) after deploy: how to fix it

By AI App Medic · Updated · Supabase · Auth · Lovable

Sign-up works, but the confirmation email, magic link, password reset or Google login lands the user on http://localhost:3000 or an old preview domain. The cause is almost always Supabase Auth's URL configuration, which still points at development values.

How Supabase decides where to send the user

Fix 1: set the Site URL and Redirect URLs

  1. Supabase dashboard > Authentication > URL Configuration.
  2. Set Site URL to your production URL, for example https://yourapp.com.
  3. Under Redirect URLs add every place users may return to:
    • https://yourapp.com/**
    • https://www.yourapp.com/** if you use www
    • your host's default domain, e.g. https://yourapp.netlify.app/**
    • http://localhost:5173/** for local development (Vite's default port)

Fix 2: pass the current origin from your code

Avoid hard-coded URLs. Use the origin the user is on:

await supabase.auth.signInWithOAuth({
  provider: 'google',
  options: { redirectTo: window.location.origin + '/auth/callback' },
});

await supabase.auth.resetPasswordForEmail(email, {
  redirectTo: window.location.origin + '/reset-password',
});

Search your code for localhost and for old preview domains; AI-generated code often hard-codes the URL it was tested on.

Fix 3: check the email templates

In Authentication > Email Templates, templates that build links from {{ .SiteURL }} always use the Site URL. Templates using {{ .ConfirmationURL }} respect the redirect your code passed (if it is allowed). If you customised the templates, make sure they still use the variable you expect.

Fix 4: OAuth providers (Google, GitHub)

In the provider's console (for example Google Cloud, then Credentials or Google Auth Platform, Clients), the authorized redirect URI must be your Supabase callback, https://<project-ref>.supabase.co/auth/v1/callback, or your custom auth domain if you set one up. Your app's own URL belongs in Supabase's Redirect URLs list, not in Google's. If Google itself shows Error 400: redirect_uri_mismatch, follow the dedicated redirect_uri_mismatch guide.

Test it properly

Use a private window and a fresh email address: sign up, confirm, log out, reset the password, and sign in with each OAuth provider. Old emails contain old links, so always test with newly sent ones. If the confirmation email never arrives, that is a different problem: Supabase auth email not sending. If you just added a custom domain, add that host to the redirect list as well (custom domain checklist).

FAQ

Why does Supabase send users to localhost:3000?

If the redirect URL your code requests is not in the allowed Redirect URLs list, Supabase falls back to the Site URL. On new projects the Site URL defaults to http://localhost:3000.

Do I need to change anything in Google Cloud for Google sign-in?

The authorized redirect URI in Google must be your Supabase callback URL (https://<project>.supabase.co/auth/v1/callback), not your app URL. Your app URL goes in Supabase's Redirect URLs.

Can I use wildcards in Supabase Redirect URLs?

Yes, for example https://your-app.netlify.app/** matches any path on that domain. Be specific in production and avoid overly broad patterns.

Related guides