mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-30 16:08:56 +00:00
fix(login): invite flow instead of email verification for users with no primary method, improve sending behaviour (#11837)
Closes #10929 # Which Problems Are Solved When a human user without a primary authentication method enters their email on the login screen, the login historically auto-sent an email code (send=true) and redirected them to the `/verify` flow. If the user was newly created via the API and already received an initial verify-email, navigating to the login page would trigger a new invite code, silently invalidating the code they received in their first email. Additionally instead of resending the same type of email (invitation) a regular email verification mail was sent # How the Problems Are Solved - Resend an invitation email instead of a email verification if a user has no method set (still in invitation state) - Conditional Code Sending: Updated `loginname.ts` to check `humanUser?.email?.isVerified`. We only auto-send a new code (`send=true`) if the user's email is already verified. Unverified users will be redirected with `send=false`, allowing them to safely enter the code they already have. - UI State Fix: Fixed an issue in `verify/page.tsx` where the send URL parameter was being checked directly as a string ("false" is truthy). By using the properly evaluated doSend boolean, the "Code Sent" alert now correctly hides itself when a new code is not explicitly sent. - Translation Updates: Refined the codeSent messaging across all locales to specify "A new code has been sent..." to provide better context to the user when they do explicitly request a resend.
This commit is contained in:
@@ -338,10 +338,16 @@ export async function sendLoginname(command: SendLoginnameCommand) {
|
||||
logger.debug("humanUser.email?.isVerified", {
|
||||
isVerified: humanUser?.email?.isVerified,
|
||||
});
|
||||
|
||||
// If the user's email is not verified, they likely already have a code from the
|
||||
// initial verification email. Auto-sending a new one here invalidates their existing code
|
||||
// and causes confusion. Only auto-send (`send=true`) if the email is already verified.
|
||||
const shouldSend = humanUser?.email?.isVerified === true;
|
||||
|
||||
const params = new URLSearchParams({
|
||||
loginName: (session?.factors?.user?.loginName ?? user.preferredLoginName) as string,
|
||||
send: "true", // set this to true to request a new code immediately
|
||||
invite: humanUser?.email?.isVerified ? "false" : "true", // sendInviteEmailCode results in an error if user is already initialized
|
||||
send: shouldSend ? "true" : "false",
|
||||
invite: "true", // always send invite code if user has no primary auth method
|
||||
});
|
||||
|
||||
if (command.requestId) {
|
||||
|
||||
Reference in New Issue
Block a user