Fix guide · updated 2026-11-14
Supabase "Email link is invalid or has expired" (otp_expired)
Email link is invalid or has expired · otp_expired · error=access_denied
Your user clicks the link in a Supabase email (confirm sign-up, magic link, password reset) and lands on your site logged out. The address bar ends with #error=access_denied&error_code=otp_expired&error_description=Email+link+is+invalid+or+has+expired. Supabase isn't down. The link was already used, replaced by a newer email, or too old when it was opened. Here's how to tell which, and how to stop it happening.
What the error means
We read the check in the source code of Supabase Auth (internal/api/verify.go). It answers otp_expired with "Email link is invalid or has expired" in exactly two cases:
- The token in the link is no longer on file. Each link works once, and Supabase deletes the old token when it sends a newer email of the same kind to the same person.
- The link is older than the expiry time. On Supabase's hosted platform, email links expire after 1 hour by default.
Supabase then sends the user to your redirect URL with the error after the # (with the PKCE flow, in the query string too). If your app doesn't read it, the user just sees your home page, logged out. If you verify codes yourself with verifyOtp(), the same problem comes back as a 403 with the code otp_expired and the message "Token has expired or is invalid". Typed codes also fail for reasons links can't, like the wrong type or a lost digit: see Supabase "Token has expired or is invalid" (email OTP).
Why a link dies before your user clicks it
1. An email scanner opened it first
Some email security systems open every link in an incoming email to check it for danger. Supabase's own docs name Safe Links in Microsoft Defender for Office 365. The scanner's visit uses up the link, so when your user clicks, it's already spent. The sign: it fails even when the person clicks within a minute, often on work or school addresses, where these scanners run.
2. A newer email replaced it
The user pressed "Sign up" twice, or "Resend", then opened the first email. Only the newest link works. Magic links and password-reset links share one slot, so asking for a magic link also cancels a reset link sent earlier, and the other way around.
3. It was already used
The user clicked it on their phone, then again on their laptop. The second click fails, even if the first one signed them in on the phone.
4. It's too old
The user signed up at night and clicked in the morning. The setting is Authentication → Sign In / Providers → Auth Providers → Email → Email OTP Expiration, in seconds. It covers every email link: confirmation, magic link, password reset, email change and invitation. Supabase strongly discourages anything above 86,400 seconds (one day).
5. Your email provider rewrote the link
If you send auth emails through your own provider with click tracking on, each link is swapped for the provider's tracking link. Supabase's docs say the links then won't work as expected and recommend turning email tracking off. Turn off click tracking for these emails.
Fix 1: catch the error and offer a new link
Whatever the cause, don't leave the user on a page that says nothing. Read the error when your app loads:
// Run once when the app starts (for example in App.tsx)
const hash = new URLSearchParams(window.location.hash.slice(1));
const query = new URLSearchParams(window.location.search);
const errorCode = hash.get('error_code') || query.get('error_code');
if (errorCode === 'otp_expired') {
// Show: "This link has expired or was already used."
// plus an email field and a "Send me a new link" button
}
The user isn't signed in at this point, so your app doesn't know their email: ask for it in the same box. The button then sends a fresh email, with the call that matches what they were waiting for:
// Sign-up confirmation
await supabase.auth.resend({ type: 'signup', email });
// Magic link: ask for a new one
await supabase.auth.signInWithOtp({ email });
// Password reset (point redirectTo at your new-password page)
await supabase.auth.resetPasswordForEmail(email, {
redirectTo: `${window.location.origin}/update-password`,
});
By default, Supabase lets one person ask for a new magic link or code only once every 60 seconds. Grey out the button for a minute after each send.
Fix 2: stop scanners from using up the link
Supabase's docs give two ways. Both change the email templates (Authentication → Email Templates in the dashboard), not your app's code alone.
Option A: send a 6-digit code instead of a link. Put {{ .Token }} in the template where the link was, and let the user type the code into your app:
const { data, error } = await supabase.auth.verifyOtp({ email, token, type: 'email' });
A scanner can read a code, but it can't use it. Take the link out of that template, though: when one email has both, opening the link uses up the code too.
Option B: link to your own page, and verify only on a button click. Scanners open pages but don't press buttons. In the "Confirm signup" template, point the link at your site with the token hash:
<a href="{{ .SiteURL }}/auth/confirm?token_hash={{ .TokenHash }}&type=email">Confirm your email</a>
Then add a page at /auth/confirm with a "Confirm" button that does this:
const params = new URLSearchParams(window.location.search);
async function onConfirmClick() {
const { error } = await supabase.auth.verifyOtp({
token_hash: params.get('token_hash'),
type: params.get('type'), // 'email' here, 'recovery' in the reset template
});
if (error) {
// Expired or already used: show the "new link" box from Fix 1
return;
}
window.location.replace('/'); // signed in
}
In the "Reset password" template, use type=recovery, and after the click send the user to your new-password page. {{ .SiteURL }} must be your live address: if it still says localhost, see Supabase login redirects to localhost after deploy.
If an AI tool built your app
Lovable, Bolt and similar tools usually wire the default link and never read the error. Paste this into your next prompt:
When the URL contains error_code=otp_expired (after # or ?), show "This link has expired or was already used" with an email field and a button that sends a new link: supabase.auth.resend({ type: 'signup', email }) for sign-up, signInWithOtp for magic links, resetPasswordForEmail for password resets. Disable the button for 60 seconds after each send. Add a page at /auth/confirm that reads token_hash and type from the URL and calls supabase.auth.verifyOtp({ token_hash, type }) only when the user clicks a Confirm button.
Then change the email template yourself, as in Fix 2: the template is a setting in your Supabase project.
Not quite your error?
- The email never arrives: Supabase: "Error sending confirmation email".
- The link opens a page that says "requested path is invalid": Supabase "requested path is invalid".
Still stuck?
Write down when the email went out and when the user clicked, and check whether a newer email went out in between. If the click was within the expiry time, on the newest email, and it still failed the first time, something else opened the link first: a scanner or a tracking link. Supabase documents the scanner problem and both fixes on its email templates page, and the expiry setting on its passwordless email page.
Other Supabase problems? See Supabase fixes.