@zeyolabs/ui 2026.11.39 → 2026.11.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/account/AuthAlert.svelte +18 -0
- package/account/AuthCard.svelte +54 -0
- package/account/InviteAccept.svelte +56 -0
- package/account/Passkeys.svelte +143 -0
- package/account/SignIn.svelte +116 -0
- package/package.json +2 -2
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
|
|
4
|
+
import Text from '../text/Text.svelte';
|
|
5
|
+
|
|
6
|
+
let { children }: { children: Snippet } = $props();
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<div class="auth-alert" role="alert"><Text color="error">{@render children()}</Text></div>
|
|
10
|
+
|
|
11
|
+
<style>
|
|
12
|
+
.auth-alert {
|
|
13
|
+
padding: 8px 10px;
|
|
14
|
+
border: 1px solid color-mix(in srgb, var(--err) 40%, transparent);
|
|
15
|
+
border-radius: var(--radius-md);
|
|
16
|
+
background: color-mix(in srgb, var(--err) 8%, transparent);
|
|
17
|
+
}
|
|
18
|
+
</style>
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
|
|
4
|
+
import Card from '../card/Card.svelte';
|
|
5
|
+
import Title from '../text/Title.svelte';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The narrow centred card the sign-in and invite pages sit in. `fullscreen` centres it in the
|
|
9
|
+
* viewport, for an app with no header around its auth pages.
|
|
10
|
+
*/
|
|
11
|
+
let {
|
|
12
|
+
accent = false,
|
|
13
|
+
brand,
|
|
14
|
+
children,
|
|
15
|
+
fullscreen = false,
|
|
16
|
+
title,
|
|
17
|
+
}: {
|
|
18
|
+
/** The title in the brand's accent colour. */
|
|
19
|
+
accent?: boolean;
|
|
20
|
+
/** A logo mark above the title. */
|
|
21
|
+
brand?: Snippet;
|
|
22
|
+
children: Snippet;
|
|
23
|
+
fullscreen?: boolean;
|
|
24
|
+
title: string;
|
|
25
|
+
} = $props();
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<div class="auth-card" class:fullscreen>
|
|
29
|
+
<Card gap="sm" padding="lg">
|
|
30
|
+
{@render brand?.()}
|
|
31
|
+
<Title color={accent ? 'accent' : undefined} level={1} size="md">{title}</Title>
|
|
32
|
+
{@render children()}
|
|
33
|
+
</Card>
|
|
34
|
+
</div>
|
|
35
|
+
|
|
36
|
+
<style>
|
|
37
|
+
.auth-card {
|
|
38
|
+
width: 100%;
|
|
39
|
+
max-width: 24rem;
|
|
40
|
+
margin: 4rem auto 0;
|
|
41
|
+
}
|
|
42
|
+
.fullscreen {
|
|
43
|
+
display: grid;
|
|
44
|
+
place-items: center;
|
|
45
|
+
max-width: none;
|
|
46
|
+
min-height: 100vh;
|
|
47
|
+
margin: 0;
|
|
48
|
+
padding: 24px;
|
|
49
|
+
}
|
|
50
|
+
.fullscreen > :global(*) {
|
|
51
|
+
width: 100%;
|
|
52
|
+
max-width: 24rem;
|
|
53
|
+
}
|
|
54
|
+
</style>
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { AuthLoads } from '@zeyolabs/kit/auth/sveltekit/loads';
|
|
3
|
+
import type { Snippet } from 'svelte';
|
|
4
|
+
|
|
5
|
+
import Text from '../text/Text.svelte';
|
|
6
|
+
import AuthAlert from './AuthAlert.svelte';
|
|
7
|
+
import AuthCard from './AuthCard.svelte';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The invite page (`/invite?token=`): who is invited to which account, and the accept button,
|
|
11
|
+
* or why it can't be accepted. `data` is the page's `AuthLoads.invite` result.
|
|
12
|
+
*/
|
|
13
|
+
let {
|
|
14
|
+
accent = false,
|
|
15
|
+
brand,
|
|
16
|
+
data,
|
|
17
|
+
fullscreen = false,
|
|
18
|
+
}: {
|
|
19
|
+
accent?: boolean;
|
|
20
|
+
brand?: Snippet;
|
|
21
|
+
data: Awaited<ReturnType<typeof AuthLoads.invite>>;
|
|
22
|
+
fullscreen?: boolean;
|
|
23
|
+
} = $props();
|
|
24
|
+
|
|
25
|
+
const mismatch = $derived(
|
|
26
|
+
data.invite && data.signedInAs && data.invite.email !== data.signedInAs.toLowerCase()
|
|
27
|
+
);
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
{#if !data.invite}
|
|
31
|
+
<AuthCard {accent} {brand} {fullscreen} title="Invitation not found">
|
|
32
|
+
<Text color="secondary">It has expired or was already used. Ask for a new one.</Text>
|
|
33
|
+
</AuthCard>
|
|
34
|
+
{:else}
|
|
35
|
+
<AuthCard {accent} {brand} {fullscreen} title="Join {data.invite.accountName}">
|
|
36
|
+
<Text color="secondary">This invitation is for <strong>{data.invite.email}</strong>.</Text>
|
|
37
|
+
{#if data.error || mismatch}
|
|
38
|
+
<AuthAlert>
|
|
39
|
+
{mismatch
|
|
40
|
+
? `You are signed in as ${data.signedInAs}. Sign out and sign in as ${data.invite.email} to accept.`
|
|
41
|
+
: 'This invitation could not be accepted.'}
|
|
42
|
+
</AuthAlert>
|
|
43
|
+
{:else}
|
|
44
|
+
<form action="/auth/invite/accept" method="post">
|
|
45
|
+
<input name="token" type="hidden" value={data.token} />
|
|
46
|
+
<button class="btn default" type="submit">Accept invitation</button>
|
|
47
|
+
</form>
|
|
48
|
+
{/if}
|
|
49
|
+
</AuthCard>
|
|
50
|
+
{/if}
|
|
51
|
+
|
|
52
|
+
<style>
|
|
53
|
+
form :global(.btn) {
|
|
54
|
+
width: 100%;
|
|
55
|
+
}
|
|
56
|
+
</style>
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { AuthLoads } from '@zeyolabs/kit/auth/sveltekit/loads';
|
|
3
|
+
|
|
4
|
+
import { invalidateAll } from '$app/navigation';
|
|
5
|
+
import { page } from '$app/state';
|
|
6
|
+
import KeyRound from '@lucide/svelte/icons/key-round';
|
|
7
|
+
import Trash2 from '@lucide/svelte/icons/trash-2';
|
|
8
|
+
import { PasskeyClient, PasskeyClientError } from '@zeyolabs/kit/auth/sessions/passkeys/client';
|
|
9
|
+
import { onMount } from 'svelte';
|
|
10
|
+
|
|
11
|
+
import Card from '../card/Card.svelte';
|
|
12
|
+
import Button from '../form/Button.svelte';
|
|
13
|
+
import Input from '../form/primitives/Input.svelte';
|
|
14
|
+
import Span from '../text/Span.svelte';
|
|
15
|
+
import Text from '../text/Text.svelte';
|
|
16
|
+
import Title from '../text/Title.svelte';
|
|
17
|
+
import AuthAlert from './AuthAlert.svelte';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The signed-in user's passkeys (`@zeyolabs/kit/auth`): list, remove, and add one in this
|
|
21
|
+
* browser. `fresh` and `passkeys` are the page's `AuthLoads.passkeys` result.
|
|
22
|
+
*/
|
|
23
|
+
let {
|
|
24
|
+
fresh,
|
|
25
|
+
passkeys,
|
|
26
|
+
placeholder = 'Name, e.g. MacBook',
|
|
27
|
+
title = 'Passkeys',
|
|
28
|
+
}: Awaited<ReturnType<typeof AuthLoads.passkeys>> & {
|
|
29
|
+
placeholder?: string;
|
|
30
|
+
title?: string;
|
|
31
|
+
} = $props();
|
|
32
|
+
|
|
33
|
+
// Feature detection only runs in the browser.
|
|
34
|
+
let supported = $state(false);
|
|
35
|
+
onMount(() => (supported = PasskeyClient.supported()));
|
|
36
|
+
|
|
37
|
+
let name = $state('');
|
|
38
|
+
let message = $state<null | string>(null);
|
|
39
|
+
let busy = $state(false);
|
|
40
|
+
|
|
41
|
+
const day = new Intl.DateTimeFormat('en-GB', { dateStyle: 'medium' });
|
|
42
|
+
|
|
43
|
+
async function add() {
|
|
44
|
+
message = null;
|
|
45
|
+
busy = true;
|
|
46
|
+
try {
|
|
47
|
+
await PasskeyClient.add(name.trim() || 'Passkey');
|
|
48
|
+
name = '';
|
|
49
|
+
await invalidateAll();
|
|
50
|
+
} catch (err) {
|
|
51
|
+
if (err instanceof PasskeyClientError && err.reauth) {
|
|
52
|
+
message = 'For security, sign out and back in, then add the passkey within 15 minutes.';
|
|
53
|
+
} else if (!PasskeyClient.isCancel(err)) {
|
|
54
|
+
message = err instanceof Error ? err.message : 'Could not add the passkey';
|
|
55
|
+
}
|
|
56
|
+
} finally {
|
|
57
|
+
busy = false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
</script>
|
|
61
|
+
|
|
62
|
+
<Card gap="sm" padding="md">
|
|
63
|
+
<Title level={2} size="xs">{title}</Title>
|
|
64
|
+
<Text color="secondary" size="sm">
|
|
65
|
+
Sign in with your fingerprint, face or device PIN instead of an email link.
|
|
66
|
+
</Text>
|
|
67
|
+
|
|
68
|
+
{#if passkeys.length}
|
|
69
|
+
<ul class="keys">
|
|
70
|
+
{#each passkeys as passkey (passkey.id)}
|
|
71
|
+
<li>
|
|
72
|
+
<KeyRound size={13} />
|
|
73
|
+
<div class="who">
|
|
74
|
+
<Span bold>{passkey.name}</Span>
|
|
75
|
+
<Span color="tertiary" size="sm">
|
|
76
|
+
Added {day.format(passkey.createdAt)}{passkey.lastUsedAt
|
|
77
|
+
? `, last used ${day.format(passkey.lastUsedAt)}`
|
|
78
|
+
: ''}
|
|
79
|
+
</Span>
|
|
80
|
+
</div>
|
|
81
|
+
<form action="/auth/passkey/delete" method="post">
|
|
82
|
+
<input name="id" type="hidden" value={passkey.id} />
|
|
83
|
+
<input name="next" type="hidden" value={page.url.pathname} />
|
|
84
|
+
<button
|
|
85
|
+
class="btn ghost-destructive sm icon"
|
|
86
|
+
aria-label="Remove {passkey.name}"
|
|
87
|
+
title="Remove"
|
|
88
|
+
type="submit"
|
|
89
|
+
>
|
|
90
|
+
<Trash2 size={13} />
|
|
91
|
+
</button>
|
|
92
|
+
</form>
|
|
93
|
+
</li>
|
|
94
|
+
{/each}
|
|
95
|
+
</ul>
|
|
96
|
+
{:else}
|
|
97
|
+
<Text color="tertiary" size="sm">No passkeys yet.</Text>
|
|
98
|
+
{/if}
|
|
99
|
+
|
|
100
|
+
{#if supported}
|
|
101
|
+
<div class="add">
|
|
102
|
+
<Input aria-label="Passkey name" maxlength={60} {placeholder} size="sm" bind:value={name} />
|
|
103
|
+
<Button disabled={busy} onclick={add} size="sm" variant="secondary">
|
|
104
|
+
<KeyRound size={13} />
|
|
105
|
+
{busy ? 'Waiting…' : 'Add passkey'}
|
|
106
|
+
</Button>
|
|
107
|
+
</div>
|
|
108
|
+
{#if !fresh}
|
|
109
|
+
<Text color="tertiary" size="sm">Adding one needs a sign-in from the last 15 minutes.</Text>
|
|
110
|
+
{/if}
|
|
111
|
+
{#if message}<AuthAlert>{message}</AuthAlert>{/if}
|
|
112
|
+
{:else}
|
|
113
|
+
<Text color="tertiary" size="sm">This browser does not support passkeys.</Text>
|
|
114
|
+
{/if}
|
|
115
|
+
</Card>
|
|
116
|
+
|
|
117
|
+
<style>
|
|
118
|
+
.keys {
|
|
119
|
+
display: flex;
|
|
120
|
+
flex-direction: column;
|
|
121
|
+
margin: 0;
|
|
122
|
+
padding: 0;
|
|
123
|
+
list-style: none;
|
|
124
|
+
}
|
|
125
|
+
.keys li {
|
|
126
|
+
display: flex;
|
|
127
|
+
align-items: center;
|
|
128
|
+
gap: 8px;
|
|
129
|
+
padding: 6px 0;
|
|
130
|
+
border-top: 1px solid var(--bds);
|
|
131
|
+
}
|
|
132
|
+
.who {
|
|
133
|
+
display: flex;
|
|
134
|
+
flex: 1;
|
|
135
|
+
flex-direction: column;
|
|
136
|
+
min-width: 0;
|
|
137
|
+
}
|
|
138
|
+
.add {
|
|
139
|
+
display: flex;
|
|
140
|
+
gap: 8px;
|
|
141
|
+
max-width: 420px;
|
|
142
|
+
}
|
|
143
|
+
</style>
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { AuthLoads } from '@zeyolabs/kit/auth/sveltekit/loads';
|
|
3
|
+
import type { Snippet } from 'svelte';
|
|
4
|
+
|
|
5
|
+
import { goto } from '$app/navigation';
|
|
6
|
+
import { page } from '$app/state';
|
|
7
|
+
import { PasskeyClient } from '@zeyolabs/kit/auth/sessions/passkeys/client';
|
|
8
|
+
import { onMount } from 'svelte';
|
|
9
|
+
|
|
10
|
+
import Button from '../form/Button.svelte';
|
|
11
|
+
import Input from '../form/primitives/Input.svelte';
|
|
12
|
+
import Span from '../text/Span.svelte';
|
|
13
|
+
import Text from '../text/Text.svelte';
|
|
14
|
+
import AuthAlert from './AuthAlert.svelte';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Passwordless sign-in (`@zeyolabs/kit/auth`): a passkey where the browser supports one, else
|
|
18
|
+
* an emailed link, and the "finish signing in" step a link lands on. `data` is the page's
|
|
19
|
+
* `AuthLoads.login` result. Put it in an `AuthCard`, or under a page title.
|
|
20
|
+
*/
|
|
21
|
+
let {
|
|
22
|
+
data,
|
|
23
|
+
footer,
|
|
24
|
+
intro,
|
|
25
|
+
}: {
|
|
26
|
+
data: Awaited<ReturnType<typeof AuthLoads.login>>;
|
|
27
|
+
/** Below everything, e.g. the Access identity the app sees. */
|
|
28
|
+
footer?: Snippet;
|
|
29
|
+
intro?: string;
|
|
30
|
+
} = $props();
|
|
31
|
+
|
|
32
|
+
// Feature detection only runs in the browser; the server renders the email form alone.
|
|
33
|
+
let supported = $state(false);
|
|
34
|
+
onMount(() => (supported = PasskeyClient.supported()));
|
|
35
|
+
|
|
36
|
+
let passkeyError = $state<null | string>(null);
|
|
37
|
+
let busy = $state(false);
|
|
38
|
+
|
|
39
|
+
async function usePasskey() {
|
|
40
|
+
passkeyError = null;
|
|
41
|
+
busy = true;
|
|
42
|
+
try {
|
|
43
|
+
// eslint-disable-next-line svelte/no-navigation-without-resolve -- server-checked same-site path
|
|
44
|
+
await goto(await PasskeyClient.signIn({ next: data.next }), { invalidateAll: true });
|
|
45
|
+
} catch (err) {
|
|
46
|
+
if (!PasskeyClient.isCancel(err)) {
|
|
47
|
+
passkeyError = err instanceof Error ? err.message : 'Passkey sign-in failed';
|
|
48
|
+
}
|
|
49
|
+
} finally {
|
|
50
|
+
busy = false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<div class="sign-in">
|
|
56
|
+
{#if data.error}
|
|
57
|
+
<AuthAlert>{data.error}</AuthAlert>
|
|
58
|
+
{/if}
|
|
59
|
+
|
|
60
|
+
{#if data.token}
|
|
61
|
+
<Text color="secondary">Finish signing in on this device.</Text>
|
|
62
|
+
<form action="/auth/verify" method="post">
|
|
63
|
+
<input name="token" type="hidden" value={data.token} />
|
|
64
|
+
<input name="next" type="hidden" value={data.next} />
|
|
65
|
+
<button class="btn default" type="submit">Sign in</button>
|
|
66
|
+
</form>
|
|
67
|
+
{:else if data.sent}
|
|
68
|
+
<Text>If that email may sign in, a link is on its way. It works once, for 15 minutes.</Text>
|
|
69
|
+
<!-- eslint-disable-next-line svelte/no-navigation-without-resolve -- the page this sits on -->
|
|
70
|
+
<a href={page.url.pathname}><Span>Use a different email</Span></a>
|
|
71
|
+
{:else}
|
|
72
|
+
{#if intro}<Text color="secondary">{intro}</Text>{/if}
|
|
73
|
+
|
|
74
|
+
{#if supported}
|
|
75
|
+
<Button disabled={busy} onclick={usePasskey}>
|
|
76
|
+
{busy ? 'Waiting for passkey…' : 'Sign in with a passkey'}
|
|
77
|
+
</Button>
|
|
78
|
+
{#if passkeyError}<AuthAlert>{passkeyError}</AuthAlert>{/if}
|
|
79
|
+
<Text centered color="tertiary" size="sm">or</Text>
|
|
80
|
+
{/if}
|
|
81
|
+
|
|
82
|
+
<form action="/auth/email" method="post">
|
|
83
|
+
<input name="next" type="hidden" value={data.next} />
|
|
84
|
+
<label for="sign-in-email"><Span bold>Email</Span></label>
|
|
85
|
+
<Input
|
|
86
|
+
id="sign-in-email"
|
|
87
|
+
name="email"
|
|
88
|
+
autocomplete="email"
|
|
89
|
+
required
|
|
90
|
+
type="email"
|
|
91
|
+
value={data.accessEmail ?? ''}
|
|
92
|
+
/>
|
|
93
|
+
<button class="btn secondary" type="submit">Email me a sign-in link</button>
|
|
94
|
+
</form>
|
|
95
|
+
{/if}
|
|
96
|
+
|
|
97
|
+
{@render footer?.()}
|
|
98
|
+
</div>
|
|
99
|
+
|
|
100
|
+
<style>
|
|
101
|
+
.sign-in,
|
|
102
|
+
form {
|
|
103
|
+
display: flex;
|
|
104
|
+
flex-direction: column;
|
|
105
|
+
gap: 12px;
|
|
106
|
+
}
|
|
107
|
+
form {
|
|
108
|
+
gap: 8px;
|
|
109
|
+
}
|
|
110
|
+
.sign-in :global(.btn) {
|
|
111
|
+
width: 100%;
|
|
112
|
+
}
|
|
113
|
+
a {
|
|
114
|
+
text-decoration: underline;
|
|
115
|
+
}
|
|
116
|
+
</style>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeyolabs/ui",
|
|
3
|
-
"version": "2026.11.
|
|
3
|
+
"version": "2026.11.40",
|
|
4
4
|
"description": "Shared Svelte 5 components, form fields and design tokens for SvelteKit 3 apps.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -170,5 +170,5 @@
|
|
|
170
170
|
"typescript": "6.0.3",
|
|
171
171
|
"typescript-eslint": "8.72.2"
|
|
172
172
|
},
|
|
173
|
-
"packageManager": "pnpm@11.
|
|
173
|
+
"packageManager": "pnpm@11.28.13"
|
|
174
174
|
}
|