Supabase "Email link is invalid or has expired" (otp_expired) on a link the user just got
New users click the confirmation, magic link, or password reset email and land on your app with error_code=otp_expired. Your own tests work. Usually a mail scanner opened the link first. How to confirm it and change the email so a scanner cannot use it up.
Free · no card
Paste your error. Get a free diagnosis by email.
Tell us what broke and we’ll email you a short diagnosis: the likely cause and what to try first. Usually within a day.
What you are seeing
- A user clicks the sign-up confirmation, magic link, invite, or password reset email within minutes, and your app opens with
#error=access_denied&error_code=otp_expired&error_description=Email+link+is+invalid+or+has+expiredin the address bar (or a blank page, if nothing reads that fragment). - It never happens to you, but it does happen to users on work or school email, Outlook, or Microsoft 365.
- Supabase API logs show
403on/auth/v1/verifyseconds after the email was sent, before the user could have opened it, and the Auth logs showotp_expired. - The user says they "clicked the newest email" but had pressed Resend more than once, or opened the link on their phone and then again on their laptop.
Why it happens
- Email prefetching. Some mail providers and security tools open every link in an incoming email to scan it (Supabase's docs name Safe Links in Microsoft Defender for Office 365). The default
{{ .ConfirmationURL }}link verifies the token on the first visit, so the scanner uses it up and the real click fails. Supabase's troubleshooting guide calls this the most common reason tokens look expired before the user can use them. - The link was already used. Links are one-time. A second click, or a click on a different device after the first one worked, fails with the same message.
- A newer email replaced it. Pressing Resend issues a new token, and the link in the older email stops working.
- It really expired. Email links and codes are valid for a limited time (one hour by default; you can change it in the Email provider settings in Supabase Auth).
- Email click tracking from your SMTP provider rewrote the links. Supabase recommends turning email tracking off for auth emails.
How to fix it
1. Confirm which cause it is
In the Supabase dashboard open Logs. In the API logs, look for 403 responses on /auth/v1/verify. In the Auth logs, look for otp_expired at the same time. A 403 within seconds of the email being sent, before a person could have clicked, means a scanner prefetched it. A 403 an hour or more later means it expired; several emails to the same address in a row means an older link was clicked. Also ask the user: did a later sign-in with their password work? For sign-up confirmations, the scanner's visit usually confirms the account anyway.
2. Option A: send a 6-digit code instead of a link
<!-- Supabase dashboard: Authentication > Email Templates (Confirm sign up / Magic link) -->
<h2>Your code</h2>
<p>Enter this code in the app: <strong>{{ .Token }}</strong></p>
// in your app, on the "check your email" screen
const { data, error } = await supabase.auth.verifyOtp({
email, // the address they signed up with
token: code, // what they typed
type: 'email',
})
if (error) setMsg(error.message)
3. Option B: keep a link, but make it open a page with a button
<!-- email template: link to YOUR page, not to Supabase's verify URL -->
<a href="{{ .SiteURL }}/auth/confirm?token_hash={{ .TokenHash }}&type=email">Confirm your email</a>
<!-- reset password template: same link with type=recovery -->
<!-- invite template: type=invite; change email template: type=email_change -->
// /auth/confirm page (React). Opening the page does nothing; the click verifies.
const params = new URLSearchParams(window.location.search)
async function confirm() {
const { error } = await supabase.auth.verifyOtp({
token_hash: params.get('token_hash'),
type: params.get('type'), // 'email', 'recovery', 'invite' or 'email_change'
})
if (error) return setMsg(error.message)
navigate(params.get('type') === 'recovery' ? '/update-password' : '/dashboard')
}
// render: <button onClick={confirm}>Confirm my email</button>
// do NOT call verifyOtp in useEffect on page load: a scanner would trigger it again
4. Make sure {{ .SiteURL }} is your live domain
Authentication > URL Configuration: Site URL must be your production domain (not localhost or a preview URL), and add your preview URLs to the Redirect URLs list. Otherwise the new link points at the wrong site.
5. Show a real message when it still fails
// on the page your links land on (default flow), read the error in the URL fragment
const hash = new URLSearchParams(window.location.hash.slice(1))
if (hash.get('error_code') === 'otp_expired') {
setMsg('That link was already used or has expired. Try signing in with your password, or request a new email (only the newest one works).')
}
6. Turn off link tracking and stop resend loops
If you send auth email through Resend, SendGrid, Postmark or similar custom SMTP, turn click tracking off for these emails. Put a 60-second cooldown on your Resend button so users do not invalidate their own links.
7. If your app is on Lovable
If you connected your own Supabase project, edit the templates in that project's dashboard as above. If the app uses Lovable Cloud, ask Lovable's agent to switch the auth emails to a code or a confirm-page link, and check the template and the /auth/confirm page it writes against the code above.
How to know it is fixed
Sign up with a fresh address at a provider you do not usually use (an Outlook or work address is the best test), wait a few minutes, then click or enter the code once. You should land signed in with no otp_expired in the URL, and the API logs should show one successful verify at the time you clicked, not one seconds after the email was sent. Repeat for password reset. Sources: Supabase: Email templates (limitations: email prefetching, email tracking), Supabase KB: OTP verification failures, otp_expired, Supabase: Auth error codes. Related: Supabase login redirects to localhost, Supabase email rate limit exceeded.