feat(auth): implement TOTP setup and management
Lint / Lint (Node/Svelte) (push) Successful in 24s
Lint / Lint (Go) (push) Successful in 28s
Lint / Lint (Python) (push) Failing after 14s
Tests / Test (Node/Svelte) (push) Successful in 18s
Tests / Test (Go) (push) Successful in 25s
Tests / Test (Python) (push) Successful in 12s

- Added TOTP support for two-factor authentication in the auth module.
- Introduced new types and interfaces for TOTP setup and token actions in the web UI.
- Created backend logic for generating and verifying TOTP secrets and tokens.
- Implemented user management features including role assignments and user CRUD operations.
- Enhanced UI components for managing users and TOTP settings.
- Added styles for optional labels and authentication reset links.
- Implemented reset code generation and validation for admin accounts.
This commit is contained in:
Gabriel20xx committed 2026-08-05 14:57:01 +02:00
1 parent 2f57554154
commit da97fd4fb1
30 files changed
+2145 -27

No files matched your search

@@ -1,6 +1,11 @@
<script lang="ts">
import type { Snippet } from 'svelte';
import type { AuthLoginInput, AuthSetupInput } from '../types';
import type {
AuthLoginInput,
AuthResetConfirm,
AuthResetRequest,
AuthSetupInput
} from '../types';
import Button from './Button.svelte';
let {
@@ -9,7 +14,10 @@
error = '',
loading = false,
onLogin,
onConfirmReset,
onRequestReset,
onSetup,
showTotp = true,
setupRequired = false,
tagline = ''
}: {
@@ -18,7 +26,10 @@
error?: string;
loading?: boolean;
onLogin?: (input: AuthLoginInput) => void | Promise<void>;
onConfirmReset?: AuthResetConfirm;
onRequestReset?: AuthResetRequest;
onSetup?: (input: AuthSetupInput) => void | Promise<void>;
showTotp?: boolean;
setupRequired?: boolean;
tagline?: string;
} = $props();
@@ -27,9 +38,14 @@
let email = $state('');
let identifier = $state('');
let password = $state('');
let totpToken = $state('');
let confirmPassword = $state('');
let submitError = $state('');
let submitting = $state(false);
let resetCode = $state('');
let resetError = $state('');
let resetOpen = $state(false);
let resetting = $state(false);
async function submit(event: SubmitEvent): Promise<void> {
event.preventDefault();
@@ -48,7 +64,7 @@
await onSetup({ username, email, password });
} else {
if (!onLogin) throw new Error('The application has not configured its login handler.');
await onLogin({ identifier, password });
await onLogin({ identifier, password, totpToken: totpToken.trim() });
}
} catch (caught) {
submitError = caught instanceof Error ? caught.message : 'Authentication failed.';
@@ -56,6 +72,38 @@
submitting = false;
}
}
async function requestReset(): Promise<void> {
resetError = '';
resetCode = '';
resetOpen = true;
try {
if (!onRequestReset) throw new Error('The application has not configured its reset handler.');
await onRequestReset();
} catch (caught) {
resetError = caught instanceof Error ? caught.message : 'Unable to request an account reset.';
}
}
async function confirmReset(): Promise<void> {
resetError = '';
const code = resetCode.trim();
if (!code) {
resetError = 'Enter the code printed in the server console.';
return;
}
resetting = true;
try {
if (!onConfirmReset) throw new Error('The application has not configured its reset handler.');
await onConfirmReset(code);
} catch (caught) {
resetError = caught instanceof Error ? caught.message : 'Unable to reset the admin account.';
} finally {
resetting = false;
}
}
</script>
<div class="sc-root sc-auth-page">
@@ -122,6 +170,20 @@
/>
</label>
{#if showTotp && !setupRequired}
<label class="sc-field">
<span class="sc-label">Authenticator code <span class="sc-label-optional">(if enabled)</span></span>
<input
autocomplete="one-time-code"
class="sc-input"
inputmode="numeric"
name="totpToken"
type="text"
bind:value={totpToken}
/>
</label>
{/if}
{#if setupRequired}
<label class="sc-field">
<span class="sc-label">Confirm password</span>
@@ -149,5 +211,35 @@
{#if children}
<div class="sc-auth-extra">{@render children()}</div>
{/if}
{#if !setupRequired && 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>
<input
aria-label="Reset code"
autocomplete="off"
class="sc-input"
placeholder="Enter reset code"
type="text"
bind:value={resetCode}
/>
{#if resetError}<p class="sc-error">{resetError}</p>{/if}
<Button
disabled={resetting}
fullWidth
size="sm"
variant="danger"
onclick={() => void confirmReset()}
>
{resetting ? 'Resetting…' : 'Confirm reset'}
</Button>
</div>
{:else}
<button class="sc-auth-reset-link" type="button" onclick={() => void requestReset()}>
Reset admin account
</button>
{/if}
{/if}
</section>
</div>