Question

Magic link works locally, on production it says 'invalid or expired'

Solved · 11 views · asked by sam_builds · edited

Email login works on localhost. On the deployed site I get the email, click the link, and land on /login?error=Email link is invalid or has expired. The link is fresh.

What I’ve tried
  1. Set the Site URL in Supabase to my domain
  2. Redeployed twice
Comment

1 answer

Marked as helpful by the asker
mira_dev · edited

Add your production URL to Authentication → URL Configuration → Redirect URLs (with /** at the end). Site URL alone is not enough, Supabase only redirects to URLs on that allow-list, otherwise it falls back and the token is consumed on the wrong page.

Second thing to check: some mail clients pre-fetch links to scan them. That consumes the one-time token before you click. Use a PKCE flow (token_hash in the URL) instead of the implicit one; @supabase/ssr does this by default.

Comment