Skip to content

fix(auth): idempotent email verification links - #3

Merged
lfaletti merged 1 commit into
masterfrom
fix/verify-email-idempotent
Nov 14, 2026
Merged

lfaletti merged 1 commit into
masterfrom
fix/verify-email-idempotent

Conversation

@lfaletti

@lfaletti lfaletti commented Nov 8, 2026

Copy link
Copy Markdown
Owner

Verifying an email with a link that was already used returned the generic 'Invalid or expired verification token' error, which looks like a broken account to the user (typical case: double click, or the mail client prefetching the link).

The verification token now carries an HMAC marker (vmk) bound to the account's current email_verified_at. verifyEmailToken returns a typed result (verified / already_verified / invalid):

  • account unverified -> verify and return the new session
  • already verified + marker matches -> already_verified, still issue a fresh session instead of an error
  • stale/superseded token or expired -> invalid (400 as before)
  • concurrent clicks: the loser re-checks and resolves as already_verified

Tokens issued before this change have no marker and keep working while the account is unverified and the JWT has not expired.

Route returns alreadyVerified; frontend shows a friendly message and logs the user in (ES/EN strings added).

Verifying an email with a link that was already used returned the generic
'Invalid or expired verification token' error, which looks like a broken
account to the user (typical case: double click, or the mail client
prefetching the link).

The verification token now carries an HMAC marker (vmk) bound to the
account's current email_verified_at. verifyEmailToken returns a typed
result (verified / already_verified / invalid):

- account unverified  -> verify and return the new session
- already verified + marker matches -> already_verified, still issue a
  fresh session instead of an error
- stale/superseded token or expired -> invalid (400 as before)
- concurrent clicks: the loser re-checks and resolves as already_verified

Tokens issued before this change have no marker and keep working while
the account is unverified and the JWT has not expired.

Route returns alreadyVerified; frontend shows a friendly message and logs
the user in (ES/EN strings added).
@vercel

vercel Bot commented Nov 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
freematch-workspace Ready Ready Preview Nov 8, 2026 1:32am UTC

@lfaletti
lfaletti merged commit 031b823 into master Nov 14, 2026
3 checks passed

This branch was successfully deployed

1 active deployment
Preview — 031b8230 Deployed Nov 8, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant