diff --git a/shared/packages/web-ui/src/lib/components/AuthPage.svelte b/shared/packages/web-ui/src/lib/components/AuthPage.svelte index 6827fb6..272f651 100644 --- a/shared/packages/web-ui/src/lib/components/AuthPage.svelte +++ b/shared/packages/web-ui/src/lib/components/AuthPage.svelte @@ -50,6 +50,11 @@ let resetOpen = $state(false); let resetting = $state(false); + // A failed status fetch tells us nothing about whether setup is actually required — + // defaulting to the setup view in that case would wrongly invite creating a new + // account when the real problem is that the server couldn't be reached. + let effectiveSetupRequired = $derived(error ? false : setupRequired); + function isTotpChallenge(caught: unknown): boolean { if (!(caught instanceof Error)) return false; const message = caught.message.toLowerCase(); @@ -65,7 +70,7 @@ event.preventDefault(); submitError = ''; - if (setupRequired && password !== confirmPassword) { + if (effectiveSetupRequired && password !== confirmPassword) { submitError = 'Passwords do not match.'; return; } @@ -73,7 +78,7 @@ submitting = true; try { - if (setupRequired) { + if (effectiveSetupRequired) { if (!onSetup) throw new Error('The application has not configured its setup handler.'); await onSetup({ username, email, password }); } else { @@ -85,11 +90,11 @@ await onLogin({ identifier, password, totpToken: totpToken.trim() }); } } catch (caught) { - if (!setupRequired && showTotp && isTotpChallenge(caught)) { + if (!effectiveSetupRequired && showTotp && isTotpChallenge(caught)) { totpRequired = true; submitError = 'Enter the six-digit authenticator code to continue.'; } else { - if (!setupRequired) { + if (!effectiveSetupRequired) { totpRequired = false; totpToken = ''; } @@ -143,7 +148,7 @@ {#if loading}

Loading...

{:else} -

{setupRequired ? 'Create your account' : 'Welcome back'}

+

{effectiveSetupRequired ? 'Create your account' : 'Welcome back'}

{/if} {#if !loading} {#if tagline} @@ -151,7 +156,7 @@ {/if}
- {#if setupRequired} + {#if effectiveSetupRequired} - {#if showTotp && !setupRequired && totpRequired} + {#if showTotp && !effectiveSetupRequired && totpRequired}