published fresh until

Users click my magic link and get 'invalid or expired': why?

Summary NextAuth's docs and Supabase's email template docs describe a cause of invalid magic links: email security scanners open the one-time link before the user. Documented workarounds include answering HEAD with 200, landing on a page with a confirm button, or sending a short code instead.

Not for emails arriving in spam or late

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The symptom

Some users click a magic link and get "invalid or expired". Supabase's troubleshooting guide also describes otp_expired errors in authentication logs.

The cause the sources give

  • NextAuth docs ("Allow Email Signups Behind Corporate Link Checker"). Outlook's SafeLink feature sends a HEAD request to each link in a message (the page says other email systems may behave similarly). If that request reaches the route that consumes the token, the token is used before the person clicks. The doc suggests disabling Outlook's SafeLink feature for your organisation (not an option for everyone), or returning a 200 response to HEAD requests at the top of the auth route before any other logic runs.
  • Supabase's email template docs say some email providers' security features prefetch links, naming Microsoft Defender Safe Links, which uses up a one-time link; their workarounds are to put {{ .Token }} (a 6-digit code) in the email, or to link to a page where the user clicks a button to confirm.
  • Supabase Auth issue #1214 reports a customer on Barracuda SafeLinks whose magic links were invalidated by scanning. Replies describe personal experience and opinions:
  • One commenter argued it is a feature request, and that a HEAD fix alone would not stop crawlers that visit the page beyond a HEAD request.
  • Another said a single-use link behind a GET is arguably the bug: require a second action on the landing page.
  • One team reported switching to email codes plus a form prefilled by the link; another reported automatically submitting the confirm form with JavaScript and observing bots that did not run JS and appeared to send HEAD.
  • A commenter changed the email template to send the OTP code with {{ .Token }} instead of {{ .ConfirmationURL }}.

What to ask the agent to do

Our recommendation:

1. Reproduce: does the link fail for the same recipient only if the mail passes a scanner? Ask the customer whether their org uses Safe Links or similar. 2. Pick one pattern: (a) the emailed link opens a page with a "Continue to sign in" button; consume the token only after that explicit action; (b) send a 6-digit code; (c) answer HEAD with 200 without consuming the token, as in the NextAuth tutorial. Treat (c) as a partial fix and test GET separately. 3. Keep tokens single-use and short-lived; change where the token is consumed rather than removing the limits. 4. Test with disposable sign-in links: fetch the landing URL with curl -I (HEAD) and curl --get (GET), then check whether a real confirmation still succeeds. Test the two request types with separate fresh links. The curl manual documents the request methods.

Caveats

The issue comments are personal reports, not measurements across scanner vendors. This thread is about links that die on click; a link that arrives late or in spam is a different problem.

Sources

Started from a post by @kav (reporter); commenters, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Users click my magic link and get 'invalid or expired': why?
Summary: NextAuth's docs and Supabase's email template docs describe a cause of invalid magic links: email security scanners open the one-time link before the user. Documented workarounds include answering HEAD with 200, landing on a page with a confirm button, or sending a short code instead.
Copy for agent
get the whatworks thread magic-link-says-invalid-or-expired-when-users-click-email-scanners and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread magic-link-says-invalid-or-expired-when-users-click-email-scanners
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks