feat(auth): enhance authentication flow with TOTP and admin reset features
- Added TOTP setup, enable, and disable functions to the API. - Implemented admin reset request and confirmation functionalities. - Updated AuthPage to handle new reset functionalities and TOTP inputs. - Enhanced auth store to manage user creation, deletion, and listing. - Improved AppShell and SettingsDialog to support user management features. - Refactored API calls for better organization and clarity.
This commit is contained in:
1 parent
ac08be0248
commit
652e81dacb
9 files changed
+4333
-3737
No files matched your search
@@ -26,11 +26,12 @@
|
||||
|
||||
<Tooltip.Provider delayDuration={300}>
|
||||
{#if auth.loading}
|
||||
<div class="flex min-h-screen items-center justify-center text-sm text-muted-fg">Loading…</div>
|
||||
<AuthPage setupRequired={auth.status?.setupRequired ?? true} loading />
|
||||
{:else if auth.error}
|
||||
<div class="flex min-h-screen items-center justify-center px-4 text-sm text-danger">
|
||||
{auth.error instanceof Error ? auth.error.message : 'Request failed.'}
|
||||
</div>
|
||||
<AuthPage
|
||||
setupRequired={auth.status?.setupRequired ?? true}
|
||||
error={auth.error instanceof Error ? auth.error.message : 'Request failed.'}
|
||||
/>
|
||||
{:else if !auth.status || auth.status.setupRequired || !auth.status.authenticated}
|
||||
<AuthPage setupRequired={auth.status?.setupRequired ?? true} />
|
||||
{:else}
|
||||
@@ -44,17 +45,33 @@
|
||||
onProfile={() => (credentialsOpen = true)}
|
||||
onSettings={() => (settingsOpen = true)}
|
||||
>
|
||||
{#snippet children()}
|
||||
{@render children?.()}
|
||||
{/snippet}
|
||||
{@render children?.()}
|
||||
</SharedAppShell>
|
||||
{/if}
|
||||
</Tooltip.Provider>
|
||||
|
||||
<SettingsDialog bind:open={settingsOpen} />
|
||||
<SettingsDialog
|
||||
bind:open={settingsOpen}
|
||||
currentRole={auth.status?.role ?? 'user'}
|
||||
currentUserId={auth.status?.id}
|
||||
onCreateUser={(input) => auth.createUser(input)}
|
||||
onDeleteUser={(id) => auth.deleteUser(id)}
|
||||
onListUsers={() => auth.listUsers()}
|
||||
onUpdateUser={(id, input) => auth.updateUser(id, input)}
|
||||
/>
|
||||
<ProfileDialog
|
||||
bind:open={credentialsOpen}
|
||||
currentUsername={auth.status?.username ?? ''}
|
||||
currentEmail={auth.status?.email ?? ''}
|
||||
currentRole={auth.status?.role ?? 'user'}
|
||||
currentUserId={auth.status?.id}
|
||||
onCreateUser={(input) => auth.createUser(input)}
|
||||
onDeleteUser={(id) => auth.deleteUser(id)}
|
||||
onListUsers={() => auth.listUsers()}
|
||||
onSave={saveProfile}
|
||||
onUpdateUser={(id, input) => auth.updateUser(id, input)}
|
||||
onTotpStatus={() => auth.totpStatus()}
|
||||
onTotpSetup={() => auth.setupTotp()}
|
||||
onTotpEnable={(token) => auth.enableTotp(token)}
|
||||
onTotpDisable={(token) => auth.disableTotp(token)}
|
||||
/>
|
||||
@@ -1,4 +1,4 @@
|
||||
<script>
|
||||
<script>
|
||||
import { Moon, Sun, SunMoon } from '@lucide/svelte';
|
||||
import Button from '$lib/components/ui/button.svelte';
|
||||
import { SettingsDialog as SharedSettingsDialog } from '@gabriel20xx/shared-code/web-ui';
|
||||
@@ -6,45 +6,62 @@
|
||||
import { currentLanguage, languages, setLanguage } from '$lib/language.svelte.js';
|
||||
import { themeState } from '$lib/theme.svelte.js';
|
||||
|
||||
let { open = $bindable(false) } = $props();
|
||||
let {
|
||||
currentRole = 'user',
|
||||
currentUserId,
|
||||
onCreateUser,
|
||||
onDeleteUser,
|
||||
onListUsers,
|
||||
onUpdateUser,
|
||||
open = $bindable(false)
|
||||
} = $props();
|
||||
|
||||
const languageItems = languages.map((language) => ({ value: language.id, label: language.label }));
|
||||
</script>
|
||||
|
||||
<SharedSettingsDialog bind:open title="Settings">
|
||||
</script>
|
||||
|
||||
<SharedSettingsDialog
|
||||
bind:open
|
||||
currentRole={currentRole}
|
||||
currentUserId={currentUserId}
|
||||
onCreateUser={onCreateUser}
|
||||
onDeleteUser={onDeleteUser}
|
||||
onListUsers={onListUsers}
|
||||
onUpdateUser={onUpdateUser}
|
||||
title="Settings"
|
||||
>
|
||||
<div>
|
||||
<span class="mb-2 block text-sm font-medium">Theme</span>
|
||||
<div class="flex w-full rounded-md border border-border p-1">
|
||||
<Button
|
||||
type="button"
|
||||
variant={themeState.mode === 'light' ? 'secondary' : 'ghost'}
|
||||
size="sm"
|
||||
class="flex-1 gap-1.5"
|
||||
onclick={() => themeState.setMode('light')}
|
||||
>
|
||||
<Sun class="size-4" />
|
||||
Light
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant={themeState.mode === 'dark' ? 'secondary' : 'ghost'}
|
||||
size="sm"
|
||||
class="flex-1 gap-1.5"
|
||||
onclick={() => themeState.setMode('dark')}
|
||||
>
|
||||
<Moon class="size-4" />
|
||||
Dark
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant={themeState.mode === 'system' ? 'secondary' : 'ghost'}
|
||||
size="sm"
|
||||
class="flex-1 gap-1.5"
|
||||
onclick={() => themeState.setMode('system')}
|
||||
>
|
||||
<SunMoon class="size-4" />
|
||||
System
|
||||
</Button>
|
||||
<div class="flex w-full rounded-md border border-border p-1">
|
||||
<Button
|
||||
type="button"
|
||||
variant={themeState.mode === 'light' ? 'secondary' : 'ghost'}
|
||||
size="sm"
|
||||
class="flex-1 gap-1.5"
|
||||
onclick={() => themeState.setMode('light')}
|
||||
>
|
||||
<Sun class="size-4" />
|
||||
Light
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant={themeState.mode === 'dark' ? 'secondary' : 'ghost'}
|
||||
size="sm"
|
||||
class="flex-1 gap-1.5"
|
||||
onclick={() => themeState.setMode('dark')}
|
||||
>
|
||||
<Moon class="size-4" />
|
||||
Dark
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant={themeState.mode === 'system' ? 'secondary' : 'ghost'}
|
||||
size="sm"
|
||||
class="flex-1 gap-1.5"
|
||||
onclick={() => themeState.setMode('system')}
|
||||
>
|
||||
<SunMoon class="size-4" />
|
||||
System
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-5">
|
||||
|
||||
Reference in new issue
Block a user