fix: prevent double triggering of verification emails (#11995)

# Which Problems Are Solved

This fixes a critical bug where initial verification emails (or invite
codes) were occasionally sent twice, invalidating the first code and
confusing users.

Previously, the initial verification email was triggered via a
`send=true` URL parameter executing inside a frontend useEffect exactly
when the `/verify` page mounted. This was fragile and prone to race
conditions caused by component remounts or partial hydration.

# How the Problems Are Solved

- Removed `send=true` from URL state and ripped out the doSend effect in
`VerifyForm.tsx`.
- Shifted execution strictly to the Next.js server. The email is now
automatically dispatched via await `initialSendVerification(...)` during
the POST requests (acting over `sendLoginname`, `register`, `password`,
`passkeys`, and `idp`).
- The login flow is now idempotent and robust against unintended
frontend re-renders.
- Refactored `checkEmailVerification()` to be async and updated the
associated unit-test coverage (all tests passing).
This commit is contained in:
Max Peintner
2026-06-29 11:42:45 +03:00
committed by GitHub
parent 14874d6546
commit 3a18cef281
14 changed files with 359 additions and 305 deletions
+1 -1
View File
@@ -168,7 +168,7 @@ export async function createNewSessionFromIdpIntent(command: CreateNewSessionCom
const humanUser = userResponse.user.type.case === "human" ? userResponse.user.type.value : undefined;
// check to see if user was verified
const emailVerificationCheck = checkEmailVerification(session, humanUser, command.organization, command.requestId);
const emailVerificationCheck = await checkEmailVerification(session, humanUser, command.organization, command.requestId);
if (emailVerificationCheck?.redirect) {
return emailVerificationCheck;