Supabase "Email link is invalid or has expired" (otp_expired): how to fix it
A user clicks the confirmation, magic link or password reset email from your Lovable, Bolt or Cursor app and lands on a URL ending in #error=access_denied&error_code=otp_expired&error_description=Email+link+is+invalid+or+has+expired. These links work once and only for a limited time. Something used it up first, or the link opened somewhere it can't finish.
Stuck on this? Get it fixed for €49.
Fixed in 48 hours or you don't pay. Launch deal for the first 5 customers (normally €79). You get the tested fix as a pull request, so nothing changes until you merge it.
Get it fixed for €491. An email scanner clicked it first
The top cause for business addresses (Outlook / Microsoft 365 Safe Links, Mimecast, Proofpoint and similar). The scanner opens every link to check it, which uses up the one-time token, so when the real person clicks, it's already spent. Tell-tale sign: Gmail users are fine and work emails always fail.
Two fixes. Either send a 6-digit code instead of a link by putting {{ .Token }} in the email template and verifying it in your app:
const { error } = await supabase.auth.verifyOtp({
email,
token: code, // the 6 digits the user typed
type: 'email', // 'signup' for confirmations, 'recovery' for resets
})
Or point the link at your own page with the token hash, and only verify when the person clicks a button. Scanners load the page, but they don't click:
<!-- email template -->
<a href="{{ .SiteURL }}/auth/confirm?token_hash={{ .TokenHash }}&type=email">Confirm</a>
// /auth/confirm page, on button click
await supabase.auth.verifyOtp({ token_hash, type })
2. It was opened in a different browser or device
With the PKCE flow (the default in @supabase/ssr), the link can only be finished in the same browser that asked for it, because that browser holds the code verifier. Requesting a magic link on a laptop and opening the email on a phone fails, often with both auth code and code verifier should be non-empty. The token_hash + verifyOtp page above works across devices.
3. It really expired, or was used twice
Links expire (one hour by default, set under Authentication → Providers → Email as the OTP expiry), and requesting a new one makes older ones stop working. Users who press "Send link" three times and click the first email will always see this error. Show the error and offer a fresh link instead of a blank page:
const params = new URLSearchParams(window.location.hash.slice(1))
if (params.get('error_code') === 'otp_expired') {
setMessage('That link has expired. Enter your email and we\'ll send a new one.')
}
// resend a confirmation
await supabase.auth.resend({ type: 'signup', email })
4. The link lands on the wrong site
If emailRedirectTo isn't in Authentication → URL Configuration → Redirect URLs, Supabase falls back to the Site URL, often localhost or an old preview. The code then arrives at an app that can't use it. See email link redirects to localhost.
5. Your app consumes the code twice
In React, calling exchangeCodeForSession inside a useEffect can run twice in development (Strict Mode) or after a re-render. The first call succeeds and the second reports an invalid or expired link. Exchange the code once, on a server route or with a guard, then redirect.
Quick checklist
- Work emails fail, Gmail works? Scanners. Use a code or a click-to-confirm page
- Different device? Use
token_hash+verifyOtp - Read
error_codefrom the URL hash and offer a resend - Redirect URL is in the allow list
- Exchange the code exactly once
Stuck on this? Get it fixed for €49.
Fixed in 48 hours or you don't pay. Launch deal for the first 5 customers (normally €79). You get the tested fix as a pull request, so nothing changes until you merge it.
Get it fixed for €49Still stuck?
Mendlark fixes this kind of problem for a fixed €49 (launch price, normally €79). We agree the problem first, test the fix and send it as a pull request, so nothing changes in your app until you merge it. If we can't fix it, you don't pay. Get the €49 fix, or start with a free scan.
Not sure what else is wrong? Paste your app link into the free instant check and get a plain-English list of problems in seconds.