Skip to content
>_VibeUnstuck

Email link is invalid or has expired

Last verified:

The fix

Email link is invalid or has expired. Supabase Auth code otp_expired. The link was already used, it aged out, or another client opened it first. Send a new link. Do not turn confirmation off.

  1. 1

    Send a new link, once

    Do not ask the user to click the old email again. Call the same sign-up, magic-link, or recovery request they started with, and use the new message. Do not loop the exchange on the expired code. That will not become valid.

  2. 2

    Exchange the code on a click, not on page load

    If the app calls exchangeCodeForSession or verifyOtp as soon as the page loads, a scanner that fetched the URL already consumed it. Show a button that runs the exchange. Keep the token in the URL until that click. Do not store the token in a log.

  3. 3

    Open the link in the browser that asked for it

    PKCE keeps the code verifier in that browser's storage. A link opened on a phone, when the form was submitted on a laptop, cannot finish. Start the flow on the device that will open the mail, or use a flow that does not depend on the stored verifier. Do not copy the verifier into the email.

  4. 4

    Check the expiry and the allow list, then stop

    Authentication, Emails shows the OTP expiry for that template. Raising it does not revive a used link. The redirect URL in the email has to match an allow-list entry, including the path. A mismatch strips the code and the exchange fails. Do not disable Confirm Email to skip the link.

Why it happens

Supabase Auth one-time links and codes expire, and a link works once. The client shows Email link is invalid or has expired. The code on that error is otp_expired. flow_state_expired is the PKCE flow state aging out, and the docs say to ask the user to sign in again. flow_state_not_found is the state already consumed, including by a retried request.

Mail scanners and some inboxes open the URL before the user does. That spends the token. The user then clicks the same link and gets otp_expired. A confirmation page that exchanges the code on a button click, instead of on the first GET, avoids the prefetch. The PKCE code verifier lives in the browser that requested the email. Opening the link on another device has nothing to exchange. The redirect URL still has to be on the project's allow list. A redirect to localhost:3000 is the other page. Email not confirmed means they never completed a link, not that this link was rejected.

The next error you'll probably hit

Once this is fixed, the usual follow-up is Email not confirmed. Supabase Auth refused sign-in because this user has not confirmed their email. The error code is email_not_confirmed.

Prompt to paste back into your AI tool

Paste this above the error.

Supabase Auth returns: Email link is invalid or has expired. error.code is <otp_expired, flow_state_expired, or unknown>. The page that handles the link is <file>. It exchanges the code on <load or a button>.

Do not turn off Confirm Email. Do not retry the same token in a loop. Do not put the service role key in the client. Do not log the token or the code verifier.

1. Tell the user to request a new email. Do not reuse the link in the message they already opened.
2. If this page calls exchangeCodeForSession or verifyOtp on load, move that call to a button click so a prefetch does not spend the token.
3. If the link was opened in a different browser than the one that requested it, say the PKCE verifier is missing and they should start again on one device.
4. Do not change the password rules or the email template unless the allow-listed redirect URL is wrong.

Common questions

+The email arrived and the first click already says the link is invalid or has expired. Why?

Something fetched the URL first, often a mail scanner, and the token is one-time. Exchange it from a button click, and send a new email for this attempt.

+Is otp_expired the same as Email not confirmed?

No. Email not confirmed means this user still has not confirmed, and sign-in is refused. otp_expired means this particular link or code is no longer valid. Send a new one.

Related errors