StackMatch

Supabase "Email link is invalid or has expired" (otp_expired) in a Lovable or Bolt app: fixes (2026)

Prices and facts checked on each tool's official site. Plans change often, so confirm before you pay.

A user clicks the confirmation, magic link or password reset email from your Lovable or Bolt app and lands on a page with error_code=otp_expired and Email link is invalid or has expired in the address. Often they clicked it within seconds. Here's why, and how to stop it.

What the error means

Supabase email links carry a one-time token. Supabase returns otp_expired when it can't find that token (it was already used, or a newer email replaced it) or when the token is older than the expiry time. By default a magic link expires after 1 hour and a user can request a new one once every 60 seconds. The same code with the message Token has expired or is invalid means the same thing for a typed 6-digit code.

Match the situation to the cause

What you seeMost likely cause
Expired instantly, often for work or school email addressesAn email security scanner (for example Microsoft Defender Safe Links) opened the link first and used it up
Works for you, fails for some usersTheir email provider or company scans links; or they clicked an older email
Signed up on a laptop, clicked the email on a phonePKCE flow: the sign-in must finish in the same browser and device where it started
Clicked the link a second timeLinks are one-time use; the first click already used it
Asked for the email twice, clicked the first oneThe newer email usually replaces the older link, so only the newest one works
Clicked it the next dayThe link really expired (1 hour by default)
Links in the email look strange or go through another domainClick tracking in your email sender (custom SMTP) rewrote the link

1. Email scanners are opening the link first

Supabase's own docs warn that some email providers prefetch links in incoming mail, for example Safe Links in Microsoft Defender for Office 365, and that this uses up the link instantly. The fix is to make sure a scanner's visit can't finish the sign-in. Supabase suggests two ways:

  • Send a code instead of a link. Put {{ .Token }} (a 6-digit code) in the email template and let the user type it into your app, which checks it with supabase.auth.verifyOtp({ email, token, type: 'email' }).
  • Link to a confirm page with a button. Make the email link open a page in your app, and only use the real Supabase link when the user clicks a Confirm button on that page.

Edit templates in the Supabase Dashboard under Authentication, Emails.

2. Turn off click tracking in your email sender

If you set up custom SMTP with an email service (see our Supabase auth emails not sending guide), its "click tracking" feature can rewrite the links in Supabase's emails. Supabase recommends turning email tracking off so the links aren't overwritten.

3. Same browser, same device

Newer Supabase setups use the PKCE flow. Supabase's docs say the code exchange must happen in the same browser and device where the sign-in started, because a secret piece (the code verifier) is saved there. If users often sign up on a computer and open email on a phone, offer the 6-digit code from step 1, which works anywhere. A related message, flow_state_expired or flow_state_not_found, means the same thing: ask the user to start the sign-in again.

4. Old links, second clicks and real expiry

Supabase links are one-time use. Tell users to use the newest email only, and add a clear "Send a new link" button on the page where the error shows up. The error is put in the page address, so your app can read error_code=otp_expired from it and show a friendly message instead of a blank page. If your links point to localhost or the wrong site, fix the Site URL and Redirect URLs in Authentication, URL Configuration; our broken after publishing guide covers that.

What to paste into Lovable or Bolt

Users get "Email link is invalid or has expired" (otp_expired) after clicking our [sign-up / magic link / password reset] email. Don't change any code yet. First tell me: whether we use the PKCE flow, what URL the email link points to, whether our email sender has click tracking on, and what the page does when the address contains error_code=otp_expired. Then propose: a 6-digit code option with supabase.auth.verifyOtp, a confirm page with a button so email scanners can't use the link, and a friendly error with a Send a new link button. Don't turn off email confirmation or Row Level Security.

When it's time to get help

Usually it's a scanner or a second click. Get a second pair of eyes when:

  • Real users can't sign up or reset their password and you're losing them.
  • You're not sure how to change the email templates without breaking sign-up.
  • You've tried the fixes and links still fail for some people.

Related guides

Sources

FAQ

What does otp_expired mean in Supabase?

Supabase couldn't use the token in that email link or code. Either it's older than the expiry time (magic links expire after 1 hour by default), it was already used, or a newer email replaced it. The message you see is usually Email link is invalid or has expired.

Why does the link say expired when I clicked it right away?

Usually something opened it before you did. Some email security tools, like Safe Links in Microsoft Defender for Office 365, visit links in incoming mail, and Supabase links only work once. Email click tracking from your email sender can also rewrite the link.

Can I open the link on a different phone or browser?

With the PKCE flow most apps use now, no. The sign-in has to finish in the same browser and device where it started, so opening the email on your phone after signing up on your laptop fails.

How do I stop this for good?

Send a 6-digit code instead of a link, or make the link open a page with a button the user clicks to confirm, so a scanner's visit doesn't use it up. Also turn off click tracking in your email sender.

Some links are referral links; we may earn a commission at no extra cost to you. It never changes our recommendations.

Newsletter

Get the monthly "which AI tool" email

One short, beginner-friendly email a month. No spam.

Form not showing? Subscribe here