This commit is contained in:
1 parent
4a37006069
commit
c4b40a9c36
1 file changed
+16
-11
@@ -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}
|
||||
<h1 id="sc-auth-title">Loading...</h1>
|
||||
{:else}
|
||||
<h1 id="sc-auth-title">{setupRequired ? 'Create your account' : 'Welcome back'}</h1>
|
||||
<h1 id="sc-auth-title">{effectiveSetupRequired ? 'Create your account' : 'Welcome back'}</h1>
|
||||
{/if}
|
||||
{#if !loading}
|
||||
{#if tagline}
|
||||
@@ -151,7 +156,7 @@
|
||||
{/if}
|
||||
|
||||
<form class="sc-form sc-auth-form" onsubmit={submit}>
|
||||
{#if setupRequired}
|
||||
{#if effectiveSetupRequired}
|
||||
<label class="sc-field">
|
||||
<span class="sc-label">Username</span>
|
||||
<input
|
||||
@@ -192,7 +197,7 @@
|
||||
<label class="sc-field">
|
||||
<span class="sc-label">Password</span>
|
||||
<input
|
||||
autocomplete={setupRequired ? 'new-password' : 'current-password'}
|
||||
autocomplete={effectiveSetupRequired ? 'new-password' : 'current-password'}
|
||||
class="sc-input"
|
||||
minlength="8"
|
||||
name="password"
|
||||
@@ -202,7 +207,7 @@
|
||||
/>
|
||||
</label>
|
||||
|
||||
{#if showTotp && !setupRequired && totpRequired}
|
||||
{#if showTotp && !effectiveSetupRequired && totpRequired}
|
||||
<label class="sc-field">
|
||||
<span class="sc-label">Authenticator code</span>
|
||||
<input
|
||||
@@ -216,7 +221,7 @@
|
||||
</label>
|
||||
{/if}
|
||||
|
||||
{#if setupRequired}
|
||||
{#if effectiveSetupRequired}
|
||||
<label class="sc-field">
|
||||
<span class="sc-label">Confirm password</span>
|
||||
<input
|
||||
@@ -236,7 +241,7 @@
|
||||
{/if}
|
||||
|
||||
<Button disabled={loading || submitting} fullWidth size="lg" type="submit">
|
||||
{loading || submitting ? 'Please wait…' : setupRequired ? 'Create account' : 'Log in'}
|
||||
{loading || submitting ? 'Please wait…' : effectiveSetupRequired ? 'Create account' : 'Log in'}
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
@@ -244,7 +249,7 @@
|
||||
<div class="sc-auth-extra">{@render children()}</div>
|
||||
{/if}
|
||||
|
||||
{#if !setupRequired && onRequestReset && onConfirmReset}
|
||||
{#if !effectiveSetupRequired && onRequestReset && onConfirmReset}
|
||||
{#if resetOpen}
|
||||
<div class="sc-auth-reset" aria-live="polite">
|
||||
<p class="sc-auth-reset-hint">A reset code has been printed to the server console.</p>
|
||||
|
||||
Reference in new issue
Block a user