From bbcf987488379151eebe48da38925d99a798ed3d Mon Sep 17 00:00:00 2001 From: Suriya Date: Tue, 21 Jul 2026 17:14:14 +0530 Subject: [PATCH] Skip the pointless password prompt before first-time password setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit checkEmailRequest only checked whether the account existed, so a first-login account (no password set yet) was still sent to the normal "enter your password" screen before the backend revealed there was no password to check against — only then did it route to the create-password step. checkEmailRequest now detects the same setup-required signal PasswordSetupRequiredError does and skips straight to it. Co-Authored-By: Claude Sonnet 5 --- src/components/LoginView.tsx | 9 +++++++-- src/services/auth.ts | 27 ++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/components/LoginView.tsx b/src/components/LoginView.tsx index 6533485..b3ce6be 100644 --- a/src/components/LoginView.tsx +++ b/src/components/LoginView.tsx @@ -57,8 +57,13 @@ export default function LoginView({ onLogin }: LoginViewProps) { setError(''); setCheckingEmail(true); try { - const emailExists = await checkEmailRequest(email); - if (emailExists) { + const result = await checkEmailRequest(email); + if (result.exists && result.needsSetup && result.userid != null) { + // No point asking for a password this account doesn't have yet — + // go straight to creating one. + setSetupUserId(result.userid); + setStep('setup'); + } else if (result.exists) { setStep('password'); } else { setError('Email not found. Please try again.'); diff --git a/src/services/auth.ts b/src/services/auth.ts index c032cd2..869e2bd 100644 --- a/src/services/auth.ts +++ b/src/services/auth.ts @@ -204,11 +204,20 @@ export async function loginRequest(email: string, password: string): Promise { +export async function checkEmailRequest(email: string): Promise { const trimmedEmail = email.trim(); let res: Response; @@ -226,16 +235,24 @@ export async function checkEmailRequest(email: string): Promise { } const json = (await res.json().catch(() => null)) as - | { code?: number; status?: boolean; message?: string } + | { code?: number; status?: boolean; message?: string; details?: unknown } | null; + // Account exists but has no password yet — fires regardless of the + // (absent) password in this probe request. See loginRequest's identical + // check for the full explanation. + const details = json?.details as { userid?: number; setup?: boolean } | undefined; + if (json?.code === 409 && details?.setup === true && typeof details.userid === 'number') { + return { exists: true, needsSetup: true, userid: details.userid }; + } + // A 409 Invalid Email code means the email does not exist. if (json && json.status === false && (json.code === 409 || json.message?.trim().toLowerCase() === 'invalid email')) { - return false; + return { exists: false, needsSetup: false }; } // Any other result (such as 403 Unauthorized email) means the email is registered. - return true; + return { exists: true, needsSetup: false }; }