Skip to content
FirstUser

For builders shipping this week

Supabase email link opens your site, but the user isn't logged in

You deployed a Lovable, Bolt, or Cursor app. The confirmation, magic-link, or password-reset email opens your live domain. The visitor is still logged out, or they are staring at the homepage with no session.

That is a different failure from the link opening http://localhost:3000. It is also different from Email link is invalid or has expired, where the address bar carries error_code=otp_expired. If they can type the password and Supabase answers that the address is not confirmed, use Email not confirmed right after signup. A shorter German note on a blank page after login is Eingeloggt – und dann eine leere Seite.

1. Read the address bar after one click

Request a new email from the published site, in a private window, and click that message once. Then look at the URL before you navigate away. Three shapes show up in the current Supabase docs:

  • ?code= is the PKCE auth code. The PKCE guide says the browser is redirected to your app with that parameter, and the code is exchanged with exchangeCodeForSession.
  • ?token_hash= together with type= is a link you built in the email template. The password guide's signup example uses type=email. Its reset example uses type=recovery. Nothing logs the user in until a route calls verifyOtp.
  • #access_token= is the implicit flow. The email templates guide says the default confirmation link redirects with the session in the URL fragment. A fragment is not sent to the server.

If the fragment or query contains error_code, stop here and follow the expired-link guide. The checks below are for a link that opens the right host and still leaves no session.

2. Exchange a code, in the browser that started it

The password guide says server-side rendering uses the PKCE flow. For client-only code, the implicit flow is the default in JavaScript. PKCE does not hand the app an access token when the link is clicked. Something on the page has to exchange the code:

const { data, error } = await supabase.auth.exchangeCodeForSession(code)

The PKCE guide says the code lasts 5 minutes and can be exchanged once. The code verifier was stored when the flow started, so the exchange has to run in that same browser. The JavaScript reference also shows a server callback reading sb_flow_id from the query and passing it as flowId. Opening the mail on a phone after signing up on a laptop fails that exchange. That cross-browser case is covered with the token-hash route in the expired-link guide.

The PKCE guide's browser example sets detectSessionInUrl: true and flowType: 'pkce'. A landing page that never creates the Supabase client leaves ?code= sitting in the URL.

3. Send token_hash to a route that calls verifyOtp

The password guide's PKCE signup template points the link at your site, not only at {{ .ConfirmationURL }}:

<a href="{{ .SiteURL }}/auth/confirm?token_hash={{ .TokenHash }}&type=email&next={{ .RedirectTo }}">
  Confirm email address
</a>

The reset template in the same guide uses type=recovery. The route at /auth/confirm reads token_hash and type, then calls verifyOtp. The email templates guide says {{ .TokenHash }} is the hashed token for building your own link, and {{ .ConfirmationURL }} is the verify URL on your Supabase project. That default link verifies first and then redirects with the session in the fragment, which a server cannot read. verifyOtp returns the session in the response, which a server route can store.

const { data, error } = await supabase.auth.verifyOtp({
  type,
  token_hash,
})

If the published site returns 404 for /auth/confirm, the route never runs. A Next.js app needs the route file the password guide shows. A static Vite app needs the host to serve the app for that path. On Netlify, the Bolt signup on Netlify guide covers the _redirects rewrite. The preview dev server often hides this, because it answers paths that are not files.

4. A fragment only exists in the browser

When the template still uses {{ .ConfirmationURL }}, the email templates guide says the session comes back in the URL fragment. The JavaScript client on that page can read it. A server component cannot. If the page they land on never creates the client, the person is on the right domain and logged out, with #access_token= still in the bar until the next navigation drops it.

The signInWithOtp reference says a magic link is sent when the template contains {{ .ConfirmationURL }}. The same fragment rule applies to that link.

5. Finish sign-in on the page you asked for

The page in the link has to be the page that performs the exchange or reads the fragment. The JavaScript references pass that page differently:

  • signUp and signInWithOtp take options.emailRedirectTo.
  • resetPasswordForEmail takes redirectTo.

The password guide says that URL has to be configured under Redirect URLs. The redirect URL guide says the Site URL is the default when the code does not pass its own redirect, and that new projects start at http://localhost:3000. If the host in the email is still localhost, fix that first. The same guide says that when you pass a redirect, replace {{ .SiteURL }} with {{ .RedirectTo }} in the template. The email templates guide says {{ .RedirectTo }} is the URL passed to signUp, signInWithOtp, resetPasswordForEmail, and the other methods it lists. A template that only prints Site URL sends people to the homepage. The homepage then has to be the page that reads the session.

For a reset, the JavaScript reference listens for PASSWORD_RECOVERY on onAuthStateChange and then calls updateUser. That listener has to be on the page redirectTo opens. Without it, the link can open the live site and never ask for a new password.

Wildcards belong on preview URLs. The redirect URL guide recommends the exact production path, and shows https://*-.vercel.app/** and https://**--my_org.netlify.app/** for preview deploys. An email requested on a preview is built for that preview origin when the code uses window.location.origin. Test from the published URL.

Checklist

  • After one click, the address is your live https host, not localhost or a preview URL.
  • You noted whether the bar has code, token_hash, or a hash with access_token or error_code.
  • A code query is exchanged with exchangeCodeForSession in the same browser that requested the email.
  • A token_hash query hits a real route that calls verifyOtp with the type from the template.
  • A hash with access_token is read by the Supabase client on that page. A server-only page cannot see it.
  • The path in the link is not a 404. A static host has to serve the app for that path.
  • emailRedirectTo or redirectTo is on Redirect URLs, and the template uses {{ .RedirectTo }} when the code passes one.
  • The reset page listens for PASSWORD_RECOVERY before it asks for a new password.
  • You requested a new email after the change. The old message still has the old link.

Verify it with a new email, then a free test

  1. Open the published URL in a private window. Do not use the editor preview.
  2. Sign up with an address that has never been used, or request a new magic link or reset from that window.
  3. Click the new message once. Ignore any older email. It still has the previous link.
  4. You should be signed in on the live domain, or, for a reset, on the page that asks for a new password. If the bar still shows code, token_hash, or access_token and the UI is logged out, the page did not finish the step above.

FirstUser's free sign-up test opens the published URL as a new visitor and signs up. When it can see the confirmation email, it follows that link. A failed step includes a screenshot. It is a sign-up test, so it does not request a password reset for you.

FAQ

The link opens my domain and I'm still logged out. What should I look at first?

The address bar after that one click. A code query parameter has to be exchanged with exchangeCodeForSession. A token_hash query parameter has to reach verifyOtp on a route that exists. An access_token in the hash is only visible to JavaScript on that page.

Why does the same email work in the preview?

The preview is usually the same browser that requested the email, and the dev server answers paths that are not files. A published site can return 404 for /auth/confirm before any client code runs, and a server-rendered page cannot read a session that arrived in the URL fragment.

I see ?code= in the URL and then I'm logged out. Is the link already used?

The PKCE guide says that code lasts 5 minutes and can be exchanged once, and that the code verifier was stored in the browser that started the flow. Exchange it there. If the bar shows error_code=otp_expired, the token was used or could not be matched, which is a different failure.

Can a free sign-up test catch a link that opens the site without a session?

The free sign-up test opens the published URL and signs up as a new visitor. It follows the confirmation email when it can see the message, and a failed step includes a screenshot. It does not request a password reset.

Checklist

Get this checklist by email

We will email this checklist to that address. Privacy policy

Sources