97 lines
3.2 KiB
Svelte
97 lines
3.2 KiB
Svelte
<script>
|
|||
|
|
import { Table2 } from '@lucide/svelte';
|
||
|
|
import Button from '$lib/components/ui/button.svelte';
|
||
|
|
import { useAuth } from '$lib/features/auth/auth.svelte.js';
|
||
|
|
|
||
|
|
let { setupRequired } = $props();
|
||
|
|
|
||
|
|
const auth = useAuth();
|
||
|
|
|
||
|
|
let username = $state('');
|
||
|
|
let password = $state('');
|
||
|
|
let confirmPassword = $state('');
|
||
|
|
let submitting = $state(false);
|
||
|
|
let error = $state('');
|
||
|
|
|
||
|
|
async function submit(event) {
|
||
|
|
event.preventDefault();
|
||
|
|
error = '';
|
||
|
|
|
||
|
|
if (setupRequired && password !== confirmPassword) {
|
||
|
|
error = 'Passwords do not match.';
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
submitting = true;
|
||
|
|
try {
|
||
|
|
if (setupRequired) {
|
||
|
|
await auth.setup(username, password);
|
||
|
|
} else {
|
||
|
|
await auth.login(username, password);
|
||
|
|
}
|
||
|
|
} catch (submitError) {
|
||
|
|
error = submitError instanceof Error ? submitError.message : 'Request failed.';
|
||
|
|
} finally {
|
||
|
|
submitting = false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
</script>
|
||
|
|
|
||
|
|
<main class="flex min-h-screen items-center justify-center bg-bg px-4 py-8">
|
||
|
|
<section class="w-full max-w-sm rounded-lg border border-border bg-surface p-6 shadow-sm">
|
||
|
|
<div class="mb-6 flex flex-col items-center gap-2 text-center">
|
||
|
|
<Table2 class="size-8 text-primary" />
|
||
|
|
<h1 class="text-xl font-semibold">CollabTable</h1>
|
||
|
|
<p class="text-sm text-muted-fg">
|
||
|
|
{setupRequired ? 'Create the admin account for this dashboard.' : 'Sign in to view this dashboard.'}
|
||
|
|
</p>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<form class="space-y-4" onsubmit={submit}>
|
||
|
|
<div>
|
||
|
|
<label for="auth-username" class="mb-1 block text-sm font-medium">Username</label>
|
||
|
|
<!-- svelte-ignore a11y_autofocus -->
|
||
|
|
<input
|
||
|
|
id="auth-username"
|
||
|
|
class="h-9 w-full rounded-md border border-border bg-bg px-3 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||
|
|
bind:value={username}
|
||
|
|
autocomplete="username"
|
||
|
|
required
|
||
|
|
autofocus
|
||
|
|
/>
|
||
|
|
</div>
|
||
|
|
<div>
|
||
|
|
<label for="auth-password" class="mb-1 block text-sm font-medium">Password</label>
|
||
|
|
<input
|
||
|
|
id="auth-password"
|
||
|
|
type="password"
|
||
|
|
class="h-9 w-full rounded-md border border-border bg-bg px-3 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||
|
|
bind:value={password}
|
||
|
|
autocomplete={setupRequired ? 'new-password' : 'current-password'}
|
||
|
|
minlength={8}
|
||
|
|
required
|
||
|
|
/>
|
||
|
|
</div>
|
||
|
|
{#if setupRequired}
|
||
|
|
<div>
|
||
|
|
<label for="auth-confirm-password" class="mb-1 block text-sm font-medium">Confirm password</label>
|
||
|
|
<input
|
||
|
|
id="auth-confirm-password"
|
||
|
|
type="password"
|
||
|
|
class="h-9 w-full rounded-md border border-border bg-bg px-3 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||
|
|
bind:value={confirmPassword}
|
||
|
|
autocomplete="new-password"
|
||
|
|
minlength={8}
|
||
|
|
required
|
||
|
|
/>
|
||
|
|
</div>
|
||
|
|
{/if}
|
||
|
|
{#if error}
|
||
|
|
<p class="text-sm text-danger">{error}</p>
|
||
|
|
{/if}
|
||
|
|
<Button type="submit" class="w-full" disabled={submitting}>
|
||
|
|
{submitting ? 'Working…' : setupRequired ? 'Create account' : 'Sign in'}
|
||
|
|
</Button>
|
||
|
|
</form>
|
||
|
|
</section>
|
||
|
|
</main>
|