← All guides

Supabase Reset Password Not Working: Fix the Link, the Session and the Page

SupabaseLovable

A user clicks “Forgot password?”, gets the email, taps the link, and nothing works. Maybe the page says Auth session missing!. Maybe it says the link is invalid or has expired, even though they clicked it a minute ago. Maybe it worked when you tested it on your laptop, but fails for a customer who opened the email on their phone. Meanwhile they are locked out of an account they may be paying for.

A password reset in Supabase has four moving parts, and each symptom points at one of them. This guide starts with a symptom table, explains each failure, and ends with a prompt to paste into Lovable, Cursor or whichever tool built your app to get a correct /update-password page.

Find your symptom

What the user seesWhere it breaksFix
No email arrivesSendingThe email never arrived
The link opens localhost, the home page or a 404Redirect URLThe link goes to the wrong page
Auth session missing! when saving the new passwordThe recovery session was never created“Auth session missing”
Works on the device that asked for the reset, fails on any otherPKCE code verifierOnly works in one browser
“Email link is invalid or has expired” (otp_expired)Token lifetime or reuseExpired or already used
The link signs the user in, but there is nowhere to type a new passwordMissing pageNo “set new password” page

How the reset flow works

Every Supabase password reset, whichever tool generated the code, goes through these steps:

  1. Request. Your “forgot password” form calls supabase.auth.resetPasswordForEmail(email, { redirectTo }). Supabase Auth emails a one-time link. To stop attackers from probing which addresses have accounts, the call returns success even when no user has that email, and in that case no email goes out (Supabase: Password-based Auth).
  2. Email link. The user clicks the link. With the default template, it points at your project’s /auth/v1/verify endpoint, which checks the token and then redirects to the redirectTo address (Supabase: Email templates).
  3. Session. Your app turns what arrives in the URL into a recovery session. How depends on the client’s flow type. In the implicit flow, the tokens arrive in the URL fragment (#access_token=...). In the PKCE flow, a ?code= arrives instead, and it must be exchanged with exchangeCodeForSession before there is a session (Supabase: PKCE flow). Either way, supabase-js fires a PASSWORD_RECOVERY event through onAuthStateChange once the session exists (Supabase: resetPasswordForEmail).
  4. New password. With that session in place, the page collects the new password and calls supabase.auth.updateUser({ password }).

Which flow does your app use? Plain createClient from @supabase/supabase-js defaults to flowType: 'implicit' (supabase-js source: GoTrueClient.ts). The createBrowserClient and createServerClient helpers in @supabase/ssr, used by Next.js apps, set flowType: 'pkce' (supabase/ssr source: createBrowserClient.ts). Open the file that creates your Supabase client and look for flowType; it decides which of the sections below apply to you.

Tool pages: /fix/supabase and /fix/lovable. If reset is one of several login problems in a Lovable app, the index in Lovable authentication errors covers the others.

The email never arrived

Missing reset emails are a sending problem, not a reset problem: the hourly cap on Supabase’s built-in sender, missing custom SMTP, or a spam folder. Work through Supabase auth emails not sending first, then come back here.

If the link lands on http://localhost:3000, your home page, or a 404, Supabase didn’t accept the redirectTo address. The address has to match an entry in the project’s Redirect URLs allow list, either exactly or through a wildcard pattern (Supabase: Redirect URLs; Supabase troubleshooting: wrong redirect URL). When it doesn’t, Supabase Auth tries the request’s referrer and, failing that, uses the Site URL (Supabase Auth on GitHub: utilities/request.go). Our localhost redirect guide walks through the full fix, including how Lovable manages the Site URL for you.

Two checks specific to reset links:

  • Pass redirectTo at all. With resetPasswordForEmail(email) and no options, the link goes to the request’s referrer, if the allow list covers it, or to the Site URL. Browsers’ default referrer policy sends only your site’s origin to another domain, so that referrer is your home page, not the forgot-password form (MDN: Referrer-Policy). Neither is the page that sets a password.
  • Check the template. If someone edited the “Reset password” email so its link starts with {{ .SiteURL }}, it ignores redirectTo entirely. See templates with a hard-coded Site URL.

If you send auth mail through an outside provider, also turn off click tracking: Supabase’s template docs say rewritten tracking links stop working.

“Auth session missing” on the new-password page

Auth session missing! doesn’t come from Supabase’s servers. It’s a client-side error in supabase-js, class AuthSessionMissingError, HTTP status 400, and its code field is undefined, so check error.name (or the isAuthSessionMissingError() helper) rather than error.code (supabase-js source: errors.ts). updateUser() returns it as error when it looks for a session and finds none.

A detail worth knowing before you blame timing: updateUser() first waits for the client to finish starting up, and in a browser that start-up includes reading the URL and exchanging a PKCE code (when detectSessionInUrl is on, which is the default) (supabase-js source: GoTrueClient.ts). So with one browser client, the error doesn’t mean the form was “too fast”. It means the session the link should have produced was never created. Check, in this order:

  1. Is the code or token still in the URL when the page loads? Open the reset link with the browser’s developer tools on the Network tab and watch the redirects. If a router guard bounces the visitor from /update-password to /login because they aren’t signed in, the ?code= or #access_token= is dropped before the Supabase client reads it. The new-password page has to be reachable while signed out.
  2. Did the exchange fail? In a PKCE app, a failed exchange leaves no session behind. Look in the Network tab for the request to token?grant_type=pkce, which is the exchange, and read its error, or log the error returned by exchangeCodeForSession if you call it yourself. flow_state_expired or flow_state_not_found means the code was too old or already used (see Expired or already used). If that request never appears, the browser had no code verifier: supabase-js raises pkce_code_verifier_not_found before sending anything, and the next section applies.
  3. Is the code exchanged twice? With detectSessionInUrl on, the browser client exchanges the code by itself. If the page also calls exchangeCodeForSession(code) by hand, the second call fails, because a code can be exchanged only once (Supabase: PKCE flow). Pick one: let the client do it, or turn detectSessionInUrl off and exchange it yourself.
  4. Does anything exchange it on the server? In a Next.js app, the code or token_hash should reach a route handler that creates the session and sets cookies before the user sees the form. Supabase’s password guide builds this as an /auth/confirm route (Supabase: Password-based Auth). If the link points straight at a server-rendered page that ignores the parameter, there’s no session.

The fix in every case is the same rule: show the password form only after the app holds a recovery session, and show “This link has expired, request a new one” when it doesn’t, instead of letting updateUser() fail.

This is the PKCE flow working as designed. When the app calls resetPasswordForEmail, the client creates a secret code verifier and stores it in that browser. Exchanging the code later needs both the code from the URL and that stored verifier, so the exchange only succeeds in the browser, on the device, where the reset began (Supabase: PKCE flow). A user who requests the reset on a laptop and opens the email on a phone has no verifier on the phone. supabase-js raises AuthPKCECodeVerifierMissingError with code pkce_code_verifier_not_found and a message that names this exact cause (supabase-js source: errors.ts). The same error appears if the browser’s storage was cleared between the request and the click; the error message lists that case too.

Apps on the implicit flow don’t hit this, because Supabase puts the session tokens straight into the redirect URL.

Supabase’s PKCE instructions for password resets change what the email contains. Instead of the default {{ .ConfirmationURL }}, the template links to your app with the hashed token, and the app calls verifyOtp with it (Supabase: Password-based Auth). verifyOtp sends the token to Supabase Auth in a POST and gets the session straight back, with no code verifier involved (Supabase: Email templates), so it works on any device.

In your own Supabase project, open Authentication → Email Templates → Reset password and point the link at your app:

<h2>Reset your password</h2>
<p><a href="{{ .SiteURL }}/update-password?token_hash={{ .TokenHash }}&type=recovery">Choose a new password</a></p>
<p>If you didn't ask for this, you can ignore this email.</p>

Supabase’s example points at an /auth/confirm server route with a next parameter, which suits Next.js. A browser-only app (React + Vite) can point straight at the page. Then, on that page:

const params = new URLSearchParams(window.location.search)
const token_hash = params.get('token_hash')

if (token_hash && params.get('type') === 'recovery') {
  const { error } = await supabase.auth.verifyOtp({ token_hash, type: 'recovery' })
  if (error) {
    // error.code is 'otp_expired' for an old or used link
    showExpiredMessage()
  }
}

Two things to keep in mind. The link now starts with {{ .SiteURL }}, so the Site URL must be your live domain, and redirectTo from the code no longer decides where the user lands. And run the verifyOtp call when the user clicks a “Continue” button rather than on page load; the next section explains why.

Apps on the Lovable built-in backend have no Supabase dashboard. Auth emails are React Email files managed under More → Emails, and Lovable’s docs warn that the auth variables and the callback links in them must stay intact or sign-in breaks (Lovable: Custom emails). Don’t hand-edit the link there. Ask Lovable to make the reset work across devices, have it explain what it changed, and run the test at the end of this guide.

The server’s answer here is HTTP 403 with code otp_expired and the message “Email link is invalid or has expired” (Supabase Auth on GitHub: verify.go). When it comes from the default link, Supabase redirects to your app with error_code=otp_expired and error_description in the URL fragment, and also in the query string for PKCE. The Auth logs record otp_expired too. The causes:

  • The link is too old. Reset links follow the project’s Email OTP Expiration setting, which defaults to one hour. Supabase notes that the same setting governs recovery, confirmation, invite and email-change links, and strongly discourages going past a day (Supabase: Passwordless email logins). Lovable apps that use its built-in backend keep this setting under More → Users → Settings → Email, adjustable anywhere between one minute and one day (Lovable: Email authentication).
  • A newer reset email was sent. Supabase keeps one recovery token per user. Sending a new reset email replaces it, so only the latest email’s link works (Supabase Auth on GitHub: mail.go). A user who presses “Send again” three times and then clicks the first email gets this error.
  • The link was already used. The token is single-use, and a successful password change clears every outstanding one-time token for the user (Supabase Auth on GitHub: models/user.go).
  • An email scanner clicked it first. Supabase’s template docs document this: some mail providers’ security scanners, such as Microsoft Defender’s Safe Links, open links in incoming mail, which spends the token before the person does (Supabase: Email templates). Supabase’s troubleshooting article suggests checking the logs for otp_expired or 403s on /verify that arrive moments after the email was sent, too fast for a human (Supabase troubleshooting: OTP verification failures). The two documented workarounds are to email the 6-digit {{ .Token }} for the user to type in, or to link to your own page and spend the token only when the user presses a button. The token_hash page above, with verifyOtp behind a button, is the second approach.
  • The PKCE code sat too long, or was reused. Separately from the email link, the ?code= handed back in the PKCE flow is valid for 5 minutes and can be exchanged once (Supabase: PKCE flow). Supabase’s error list describes flow_state_expired and flow_state_not_found, and notes that a retried request can destroy the flow state (Supabase: Auth error codes).

Whatever the cause, the page should say so in plain words and offer a button that sends a new email, not a raw error.

There’s no “set new password” page at all

If your build has a “Forgot password?” form and nothing after it, the reset link signs the user in through the recovery session and drops them on the dashboard, with no prompt for a new password. The user is in, but the password they forgot is still the only one on the account.

Lovable’s docs say it builds the reset flow (request, email, new password) when it sets up email sign-in (Lovable: Email authentication), but check that your build actually has all three steps. A correct page needs to:

  • Be reachable while signed out, and match the redirectTo (or template link) exactly.
  • Create the recovery session: verifyOtp for a token_hash link, the automatic exchange (or one manual exchangeCodeForSession) for a ?code=, or the URL fragment for the implicit flow.
  • Show the form only once getSession() returns a session or PASSWORD_RECOVERY has fired.
  • Ask for the new password twice, then call updateUser({ password }).
  • Handle errors by code: same_password (the new password matches the old one), weak_password (it fails your password rules), and otp_expired or a missing session (offer a fresh email) (Supabase: Auth error codes).
  • On success, confirm it and send the user on, for example to the login page.

If your project requires the current password for password changes (Lovable turns Require current password for password changes on by default for new projects, per its email auth docs), the reset still works: Supabase’s server skips that check when the session came from a recovery link (Supabase Auth on GitHub: api/user.go). Don’t let the AI add a “current password” field to the reset page.

Prompt to build a correct /update-password page

Our password reset is broken. Build or fix the reset flow with Supabase Auth:

1. "Forgot password" page: call supabase.auth.resetPasswordForEmail(email,
   { redirectTo: `${window.location.origin}/update-password` }). Always show
   "If an account exists, we've sent a link", whatever the result.
2. /update-password must be reachable while signed out. Do not put it behind
   the auth guard or redirect it to /login.
3. On load, create the recovery session exactly once:
   - If the URL has token_hash and type=recovery, show a "Continue" button.
     On click, call supabase.auth.verifyOtp({ token_hash, type: 'recovery' }).
   - If the URL has ?code=, let the Supabase client exchange it automatically
     (detectSessionInUrl). Do not also call exchangeCodeForSession.
   - Then confirm a session exists with supabase.auth.getSession() or the
     PASSWORD_RECOVERY event from onAuthStateChange.
4. Only when a session exists, show "New password" and "Confirm password",
   then call supabase.auth.updateUser({ password }). Do not ask for the
   current password.
5. Errors: same_password -> "Pick a password that differs from your current one";
   weak_password -> show the rule it failed; otp_expired,
   pkce_code_verifier_not_found, flow_state_expired, flow_state_not_found or
   AuthSessionMissingError (check error.name) -> "This link has expired or was
   opened on a different device" plus a button to send a new email.
6. On success, show "Password updated" and go to /login.
Tell me which Supabase client and flowType the app uses, and list every file
you change, before applying anything.

Test it end to end

Testing in the browser that requested the reset hides the cross-device bug. Run this on the live domain:

  1. Request a reset for a real test account, from a desktop browser.
  2. Open the email in a real inbox on a different device or browser (a phone works), and click the link once.
  3. Set a new password. Confirm the success message.
  4. Sign out, then sign in with the new password. Then try the old one, which should fail with invalid_credentials.
  5. Click the same email link again. You should get your friendly “expired” message, not a blank page or a raw error.
  6. Request two resets in a row and click the first email. Same friendly message.

If your users are on company mail protected by a link scanner such as Microsoft Defender’s Safe Links, test with one of those addresses too. For more checks on a Lovable build that misbehaves after publishing, see Lovable app not working.

FAQ

Your app uses the PKCE flow, and the secret it needs to finish the exchange is stored only in the browser that requested the reset. The phone doesn’t have it, so the exchange fails with pkce_code_verifier_not_found, and the page then reports a missing session. Switch the reset email to a token_hash link verified with verifyOtp({ token_hash, type: 'recovery' }), which doesn’t need that secret.

Why does the reset page say “Auth session missing”?

updateUser() ran without a session. The link’s code or tokens never turned into one: the page redirected away before the client read the URL, the PKCE exchange failed (another device, an old code, or a second exchange), or no server route handled the parameter. Gate the form on an existing session and show a friendly “request a new link” message otherwise.

Yes. On your own Supabase project, edit Authentication → Email Templates → Reset password; {{ .ConfirmationURL }}, {{ .TokenHash }}, {{ .SiteURL }} and {{ .RedirectTo }} are the variables you’ll use for the link (Supabase: Email templates). With Lovable’s built-in backend, customize the wording under More → Emails and ask Lovable for link changes, since its docs say the callback links must stay intact.

Is it safe to let users reset a password without being signed in?

Yes, that’s the point of the link. Clicking it proves the person controls the email address, and Supabase turns that proof into a recovery session that can set a new password. The protections are built in: the request form doesn’t tell anyone whether an account is registered, the link is single-use and expires (one hour by default), only the newest link works, and Supabase skips the “current password” check only for recovery sessions. When the password changes, Supabase ends all of that user’s other sessions (Supabase Auth on GitHub: models/user.go), which other devices see as Refresh Token Not Found. Supabase can also send a “Password changed” security notification if you turn it on.

Does this work the same on Lovable Cloud?

The mechanics are the same: Lovable’s built-in backend (Cloud) is built on Supabase’s open-source foundation (Lovable: Built-in backend), so the same calls, error codes and link lifetimes apply. What differs is where you change things. Publishing points the Site URL at your published address, unless the Site URL is already on your own domain. Lovable adds a custom domain to the redirect URLs when you connect one, and it rejects localhost in that list, so test locally on 127.0.0.1 (Lovable: Users and authentication). Email settings, including OTP expiration and the password rules, are under More → Users → Settings → Email, and email templates under More → Emails. If your Lovable app is linked to a separate Supabase project you created, everything in this guide applies as written, in the Supabase dashboard.

Comments

Add a comment

Generated for you. Click to type your own.

Required. Never shown on the page. Privacy policy.

Basic markdown: **bold**, *italic*, `code`, lists, quotes, and fenced code blocks. HTML shows as plain text.

Your draft stays on this device until you post.