@nebulr-group/bridge-svelte 1.0.0-alpha.2 → 1.0.0-alpha.4
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/dist/components/auth/BridgeAuthRoutes.svelte +4 -1
- package/dist/components/auth/MagicLinkLanding.svelte +114 -0
- package/dist/components/auth/MagicLinkLanding.svelte.d.ts +15 -0
- package/dist/components/auth/SetPassword.svelte +1 -1
- package/dist/components/auth/SignInForm.svelte +54 -7
- package/dist/components/auth/SignUpForm.svelte +10 -5
- package/dist/components/auth/VerifyEmail.svelte +35 -13
- package/dist/components/auth/finish-link.d.ts +16 -0
- package/dist/components/auth/finish-link.js +45 -0
- package/dist/core/messages.d.ts +1 -1
- package/dist/core/messages.js +60 -0
- package/dist/core/routes.d.ts +1 -1
- package/dist/core/routes.js +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +2 -2
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<BridgeAuthRoutes />
|
|
6
6
|
|
|
7
7
|
Serves sign-in, sign-up, verify-email, forgot-password, set-password,
|
|
8
|
-
invite, workspaces and
|
|
8
|
+
invite, workspaces, handoff and magic-link (a sign-in link's landing). An unknown page gets the app's own 404.
|
|
9
9
|
|
|
10
10
|
Customising, in rungs:
|
|
11
11
|
1. `--bridge-*` CSS tokens restyle the forms.
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
import InviteLanding from './InviteLanding.svelte';
|
|
35
35
|
import WorkspaceChooser from './WorkspaceChooser.svelte';
|
|
36
36
|
import HandoffSignIn from './HandoffSignIn.svelte';
|
|
37
|
+
import MagicLinkLanding from './MagicLinkLanding.svelte';
|
|
37
38
|
|
|
38
39
|
interface Props {
|
|
39
40
|
/** Replaces everything around the form, on every page. */
|
|
@@ -71,6 +72,8 @@
|
|
|
71
72
|
<SetPassword headingSnippet={pageHeading} {messages} />
|
|
72
73
|
{:else if p === 'invite'}
|
|
73
74
|
<InviteLanding headingSnippet={pageHeading} {messages} />
|
|
75
|
+
{:else if p === 'magic-link'}
|
|
76
|
+
<MagicLinkLanding headingSnippet={pageHeading} {messages} />
|
|
74
77
|
{:else if p === 'handoff'}
|
|
75
78
|
<HandoffSignIn headingSnippet={pageHeading} {messages} />
|
|
76
79
|
{:else if p === 'workspaces'}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Signs in from a sign-in link (a magic link), on the device that asked for
|
|
3
|
+
it. Opened on another device it says so, and the link still works on the
|
|
4
|
+
right one. The link works once: opened again, it says the link is no
|
|
5
|
+
longer valid.
|
|
6
|
+
With `storage: 'memory'` the verifier waited in localStorage, which every
|
|
7
|
+
tab of the origin shares, so the tab the link opens in signs in itself and
|
|
8
|
+
holds the session in its own memory.
|
|
9
|
+
-->
|
|
10
|
+
<script lang="ts">
|
|
11
|
+
import type { Snippet } from 'svelte';
|
|
12
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
13
|
+
import { onMount } from 'svelte';
|
|
14
|
+
import { goto } from '$app/navigation';
|
|
15
|
+
import { isBridgeError, type SignInStep, type WorkspaceChoice } from '@nebulr-group/bridge-auth-core';
|
|
16
|
+
import { getBridge, peekConfig } from '../../core/client.js';
|
|
17
|
+
import type { BridgeMessages } from '../../core/config.js';
|
|
18
|
+
import { errorMessage, translator } from '../../core/i18n.js';
|
|
19
|
+
import AuthFormWrapper from '../shared/AuthFormWrapper.svelte';
|
|
20
|
+
import Alert from '../shared/Alert.svelte';
|
|
21
|
+
import Spinner from '../shared/Spinner.svelte';
|
|
22
|
+
import WorkspaceChooser from './WorkspaceChooser.svelte';
|
|
23
|
+
import { takeEmailLink } from './email-link.js';
|
|
24
|
+
import { bounded, leave } from './finish-link.js';
|
|
25
|
+
|
|
26
|
+
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
27
|
+
/** The link's token. @default read from the page's address */
|
|
28
|
+
token?: string;
|
|
29
|
+
headingSnippet?: Snippet;
|
|
30
|
+
/** Called once signed in. Without it, the page goes to `auth.afterSignIn`. */
|
|
31
|
+
onSignIn?: () => void;
|
|
32
|
+
onError?: (error: unknown) => void;
|
|
33
|
+
messages?: BridgeMessages;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let { token = undefined, headingSnippet, onSignIn, onError, messages, class: className, style, ...rest }: Props = $props();
|
|
37
|
+
|
|
38
|
+
const t = $derived(translator(messages));
|
|
39
|
+
const config = peekConfig();
|
|
40
|
+
const authBase = config?.authBase ?? '/auth';
|
|
41
|
+
|
|
42
|
+
type State =
|
|
43
|
+
| { step: 'working' }
|
|
44
|
+
| { step: 'signed-in'; to: string }
|
|
45
|
+
| { step: 'workspace'; workspaces: readonly WorkspaceChoice[]; choose: (id: string) => Promise<SignInStep> }
|
|
46
|
+
| { step: 'failed'; message: string; kind: string | null };
|
|
47
|
+
let view = $state<State>({ step: 'working' });
|
|
48
|
+
|
|
49
|
+
async function finish() {
|
|
50
|
+
if (onSignIn) {
|
|
51
|
+
onSignIn();
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
// Signing in runs the route guard again, and that newer navigation can cancel this one: go again, then offer a link.
|
|
55
|
+
const to = config?.afterSignIn ?? '/';
|
|
56
|
+
const here = location.pathname;
|
|
57
|
+
if (!(await leave(() => goto(to, { invalidateAll: true }), () => location.pathname !== here))) view = { step: 'signed-in', to };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function fail(error: unknown) {
|
|
61
|
+
const kind = isBridgeError(error) ? error.kind : null;
|
|
62
|
+
view = { step: 'failed', message: kind === 'wrong-device' ? t('magicLink.wrongDevice') : errorMessage(error, t, 'link.error.invalid'), kind };
|
|
63
|
+
onError?.(error);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function follow(step: SignInStep) {
|
|
67
|
+
if (step.done) await finish();
|
|
68
|
+
else view = { step: 'workspace', workspaces: step.workspaces, choose: step.choose };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
onMount(() => {
|
|
72
|
+
const found = token ?? takeEmailLink('magic-link');
|
|
73
|
+
if (found === null) {
|
|
74
|
+
view = { step: 'failed', message: t('verify.missingLink'), kind: null };
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
bounded(getBridge().magicLink.finish(found)).then(follow).catch(fail);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
async function choose(id: string) {
|
|
81
|
+
if (view.step !== 'workspace') return;
|
|
82
|
+
try {
|
|
83
|
+
await follow(await view.choose(id));
|
|
84
|
+
} catch (error) {
|
|
85
|
+
fail(error);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
</script>
|
|
89
|
+
|
|
90
|
+
{#if view.step === 'working'}
|
|
91
|
+
<AuthFormWrapper heading={null} class={className} {style} data-bridge-magic-link="working" {...rest}>
|
|
92
|
+
<div class="bridge-auth-settling" data-bridge-auth-settling>
|
|
93
|
+
<Spinner size={24} />
|
|
94
|
+
<span>{t('magicLink.finishing')}</span>
|
|
95
|
+
</div>
|
|
96
|
+
</AuthFormWrapper>
|
|
97
|
+
{:else if view.step === 'signed-in'}
|
|
98
|
+
<AuthFormWrapper heading={t('login.heading')} {headingSnippet} class={className} {style} data-bridge-magic-link="signed-in" {...rest}>
|
|
99
|
+
<div class="bridge-form-footer">
|
|
100
|
+
<a href={view.to} class="bridge-link">{t('invite.continue')}</a>
|
|
101
|
+
</div>
|
|
102
|
+
</AuthFormWrapper>
|
|
103
|
+
{:else if view.step === 'workspace'}
|
|
104
|
+
<AuthFormWrapper heading={t('workspace.chooseHeading')} {headingSnippet} class={className} {style} data-bridge-magic-link="workspace" {...rest}>
|
|
105
|
+
<WorkspaceChooser workspaces={view.workspaces} onChoose={choose} {messages} />
|
|
106
|
+
</AuthFormWrapper>
|
|
107
|
+
{:else}
|
|
108
|
+
<AuthFormWrapper heading={t('login.heading')} {headingSnippet} class={className} {style} data-bridge-magic-link="failed" data-error-kind={view.kind} {...rest}>
|
|
109
|
+
<Alert variant="error">{view.message}</Alert>
|
|
110
|
+
<div class="bridge-form-footer">
|
|
111
|
+
<a href={`${authBase}/sign-in`} class="bridge-link">{t('action.backToSignIn')}</a>
|
|
112
|
+
</div>
|
|
113
|
+
</AuthFormWrapper>
|
|
114
|
+
{/if}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
import type { BridgeMessages } from '../../core/config.js';
|
|
4
|
+
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
5
|
+
/** The link's token. @default read from the page's address */
|
|
6
|
+
token?: string;
|
|
7
|
+
headingSnippet?: Snippet;
|
|
8
|
+
/** Called once signed in. Without it, the page goes to `auth.afterSignIn`. */
|
|
9
|
+
onSignIn?: () => void;
|
|
10
|
+
onError?: (error: unknown) => void;
|
|
11
|
+
messages?: BridgeMessages;
|
|
12
|
+
}
|
|
13
|
+
declare const MagicLinkLanding: import("svelte").Component<Props, {}, "">;
|
|
14
|
+
type MagicLinkLanding = ReturnType<typeof MagicLinkLanding>;
|
|
15
|
+
export default MagicLinkLanding;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
<!--
|
|
2
|
-
Sign in with email and password,
|
|
3
|
-
|
|
4
|
-
sent here from
|
|
2
|
+
Sign in with email and password, or with a sign-in link sent by email (a
|
|
3
|
+
magic link), then pick a workspace when the person has several. On success
|
|
4
|
+
it calls `onSignIn`, or goes to the page the person was sent here from
|
|
5
|
+
(else `auth.afterSignIn`).
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
The form shows the methods the app's sign-in options list: the password
|
|
8
|
+
fields when it offers passwords, "Email me a sign-in link" when it offers
|
|
9
|
+
links. Other methods (email codes, passkeys, company login, a second step)
|
|
10
|
+
arrive as new sign-in steps and join the same way, without a new API.
|
|
9
11
|
-->
|
|
10
12
|
<script lang="ts">
|
|
11
13
|
import type { Snippet } from 'svelte';
|
|
@@ -71,12 +73,14 @@
|
|
|
71
73
|
let loading = $state(false);
|
|
72
74
|
let failure = $state<string | null>(null);
|
|
73
75
|
let notice = $state<string | null>(null);
|
|
76
|
+
let linkSent = $state(false);
|
|
74
77
|
let options = $state<SignInOptions | null>(null);
|
|
75
78
|
let choice = $state<{ workspaces: readonly WorkspaceChoice[]; choose: (id: string) => Promise<SignInStep> } | null>(null);
|
|
76
79
|
let settled = $state(false);
|
|
77
80
|
|
|
78
81
|
const signUpShown = $derived(showSignupLink ?? options?.signUp ?? true);
|
|
79
82
|
const passwordOffered = $derived(options === null || options.methods.includes('password'));
|
|
83
|
+
const linkOffered = $derived(options !== null && options.methods.includes('magicLink'));
|
|
80
84
|
|
|
81
85
|
onMount(() => {
|
|
82
86
|
// Why the last session ended: told by the client as it happened, or read from the session on a fresh page.
|
|
@@ -128,6 +132,23 @@
|
|
|
128
132
|
}
|
|
129
133
|
}
|
|
130
134
|
|
|
135
|
+
/** Asks for a sign-in link to the address typed. The answer is the same whether or not it has an account. */
|
|
136
|
+
async function sendLink(event?: Event) {
|
|
137
|
+
event?.preventDefault();
|
|
138
|
+
if (loading || !email.trim()) return;
|
|
139
|
+
failure = null;
|
|
140
|
+
notice = null;
|
|
141
|
+
loading = true;
|
|
142
|
+
try {
|
|
143
|
+
await getBridge().magicLink.start(email.trim());
|
|
144
|
+
linkSent = true;
|
|
145
|
+
} catch (error) {
|
|
146
|
+
fail(error);
|
|
147
|
+
} finally {
|
|
148
|
+
loading = false;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
131
152
|
async function choose(id: string) {
|
|
132
153
|
if (choice === null) return;
|
|
133
154
|
try {
|
|
@@ -161,7 +182,9 @@
|
|
|
161
182
|
>
|
|
162
183
|
{#if notice}<Alert variant="info">{notice}</Alert>{/if}
|
|
163
184
|
{#if failure}<Alert variant="error">{failure}</Alert>{/if}
|
|
164
|
-
{#if
|
|
185
|
+
{#if linkSent}
|
|
186
|
+
<Alert variant="info">{t('magicLink.sent')}</Alert>
|
|
187
|
+
{:else if passwordOffered}
|
|
165
188
|
<form onsubmit={submit}>
|
|
166
189
|
<div class="bridge-form-group">
|
|
167
190
|
<label for="login-email">{t('field.email')}</label>
|
|
@@ -196,6 +219,30 @@
|
|
|
196
219
|
<a href={forgotPasswordHref ?? `${authBase}/forgot-password`} class="bridge-link">{t('login.forgotPassword')}</a>
|
|
197
220
|
</div>
|
|
198
221
|
{/if}
|
|
222
|
+
{#if linkOffered}
|
|
223
|
+
<div class="bridge-divider" data-bridge-sign-in-or>{t('magicLink.or')}</div>
|
|
224
|
+
<button type="button" class="bridge-btn bridge-btn-secondary" data-bridge-magic-link-send onclick={sendLink} disabled={loading || !email.trim()}>
|
|
225
|
+
{t('magicLink.send')}
|
|
226
|
+
</button>
|
|
227
|
+
{/if}
|
|
228
|
+
</form>
|
|
229
|
+
{:else if linkOffered}
|
|
230
|
+
<form onsubmit={sendLink} data-bridge-magic-link-form>
|
|
231
|
+
<div class="bridge-form-group">
|
|
232
|
+
<label for="login-email">{t('field.email')}</label>
|
|
233
|
+
<input
|
|
234
|
+
id="login-email"
|
|
235
|
+
type="email"
|
|
236
|
+
autocomplete="username"
|
|
237
|
+
placeholder={t('placeholder.email')}
|
|
238
|
+
required
|
|
239
|
+
bind:value={email}
|
|
240
|
+
disabled={loading}
|
|
241
|
+
/>
|
|
242
|
+
</div>
|
|
243
|
+
<button type="submit" class="bridge-btn bridge-btn-primary" data-bridge-magic-link-send disabled={loading || !email.trim()}>
|
|
244
|
+
{#if loading}<Spinner size={16} />{/if} {t('magicLink.send')}
|
|
245
|
+
</button>
|
|
199
246
|
</form>
|
|
200
247
|
{/if}
|
|
201
248
|
|
|
@@ -81,7 +81,9 @@
|
|
|
81
81
|
let sentTo = $state<string | null>(null);
|
|
82
82
|
let options = $state<SignInOptions | null>(null);
|
|
83
83
|
|
|
84
|
-
const minLength = $derived(options?.password
|
|
84
|
+
const minLength = $derived(options?.password?.minLength ?? 8);
|
|
85
|
+
/** An app that offers sign-in links only takes no password: the person signs in by link. */
|
|
86
|
+
const passwordOffered = $derived(options === null || options.methods.includes('password'));
|
|
85
87
|
// An invite is its own way in, whether or not the app takes sign-ups.
|
|
86
88
|
const closed = $derived(!invite && options !== null && !options.signUp);
|
|
87
89
|
let stopRelay: (() => void) | null = null;
|
|
@@ -98,11 +100,12 @@
|
|
|
98
100
|
event.preventDefault();
|
|
99
101
|
if (loading) return;
|
|
100
102
|
failure = null;
|
|
101
|
-
if (password.length < minLength) {
|
|
103
|
+
if (passwordOffered && password.length < minLength) {
|
|
102
104
|
failure = t('password.tooShort', { count: minLength });
|
|
103
105
|
return;
|
|
104
106
|
}
|
|
105
107
|
loading = true;
|
|
108
|
+
const secret = passwordOffered ? { password } : {};
|
|
106
109
|
const address = email.trim();
|
|
107
110
|
const names = {
|
|
108
111
|
...(firstName.trim() ? { firstName: firstName.trim() } : {}),
|
|
@@ -111,14 +114,14 @@
|
|
|
111
114
|
try {
|
|
112
115
|
if (invite) {
|
|
113
116
|
// Signed in at once, in the inviting workspace: the invite's link proved the address.
|
|
114
|
-
await getBridge().invites.signUp({ token: invite,
|
|
117
|
+
await getBridge().invites.signUp({ token: invite, ...secret, ...names });
|
|
115
118
|
if (onSignIn) onSignIn();
|
|
116
119
|
else void goto(config?.afterSignIn ?? '/', { invalidateAll: true });
|
|
117
120
|
return;
|
|
118
121
|
}
|
|
119
122
|
await getBridge().signUp.start({
|
|
120
123
|
email: address,
|
|
121
|
-
|
|
124
|
+
...secret,
|
|
122
125
|
...names,
|
|
123
126
|
...(workspace === 'ask' ? { workspace: workspaceName.trim() || true } : workspace ? { workspace: true } : {}),
|
|
124
127
|
});
|
|
@@ -172,6 +175,7 @@
|
|
|
172
175
|
<input id="signup-email" type="email" autocomplete="email" placeholder={t('placeholder.email')} required bind:value={email} disabled={loading} />
|
|
173
176
|
</div>
|
|
174
177
|
{/if}
|
|
178
|
+
{#if passwordOffered}
|
|
175
179
|
<div class="bridge-form-group">
|
|
176
180
|
<label for="signup-password">{t('field.password')}</label>
|
|
177
181
|
<PasswordInput
|
|
@@ -186,13 +190,14 @@
|
|
|
186
190
|
hideLabel={t('action.hidePassword')}
|
|
187
191
|
/>
|
|
188
192
|
</div>
|
|
193
|
+
{/if}
|
|
189
194
|
{#if workspace === 'ask' && !invite}
|
|
190
195
|
<div class="bridge-form-group">
|
|
191
196
|
<label for="signup-workspace">{t('field.workspaceName')}</label>
|
|
192
197
|
<input id="signup-workspace" type="text" autocomplete="organization" bind:value={workspaceName} disabled={loading} />
|
|
193
198
|
</div>
|
|
194
199
|
{/if}
|
|
195
|
-
<button type="submit" class="bridge-btn bridge-btn-primary" disabled={loading || (!invite && !email.trim()) || !password}>
|
|
200
|
+
<button type="submit" class="bridge-btn bridge-btn-primary" disabled={loading || (!invite && !email.trim()) || (passwordOffered && !password)}>
|
|
196
201
|
{#if loading}<Spinner size={16} />{:else}{t('signup.submit')}{/if}
|
|
197
202
|
</button>
|
|
198
203
|
</form>
|
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
With `storage: 'memory'` the session lives only in the tab that started the
|
|
7
7
|
sign-up, so this page first hands the link to that tab; when one takes it,
|
|
8
8
|
this page says to go on there. When none does, this page finishes itself.
|
|
9
|
+
|
|
10
|
+
Every wait has a bound: finishing fails with an error after a while, and
|
|
11
|
+
once signed in the page goes on, or offers a link when it cannot.
|
|
9
12
|
-->
|
|
10
13
|
<script lang="ts">
|
|
11
14
|
import type { Snippet } from 'svelte';
|
|
@@ -22,6 +25,7 @@
|
|
|
22
25
|
import Spinner from '../shared/Spinner.svelte';
|
|
23
26
|
import WorkspaceChooser from './WorkspaceChooser.svelte';
|
|
24
27
|
import { takeEmailLink } from './email-link.js';
|
|
28
|
+
import { bounded, leave } from './finish-link.js';
|
|
25
29
|
|
|
26
30
|
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
27
31
|
/** The link's token. @default read from the page's address */
|
|
@@ -42,13 +46,20 @@
|
|
|
42
46
|
type State =
|
|
43
47
|
| { step: 'working' }
|
|
44
48
|
| { step: 'continued' }
|
|
49
|
+
| { step: 'signed-in'; to: string }
|
|
45
50
|
| { step: 'workspace'; workspaces: readonly WorkspaceChoice[]; choose: (id: string) => Promise<SignInStep> }
|
|
46
51
|
| { step: 'failed'; message: string; kind: string | null };
|
|
47
52
|
let view = $state<State>({ step: 'working' });
|
|
48
53
|
|
|
49
|
-
function finish() {
|
|
50
|
-
if (onSignIn)
|
|
51
|
-
|
|
54
|
+
async function finish() {
|
|
55
|
+
if (onSignIn) {
|
|
56
|
+
onSignIn();
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
// Signing in runs the route guard again, and that newer navigation can cancel this one: go again, then offer a link.
|
|
60
|
+
const to = config?.afterSignIn ?? '/';
|
|
61
|
+
const here = location.pathname;
|
|
62
|
+
if (!(await leave(() => goto(to, { invalidateAll: true }), () => location.pathname !== here))) view = { step: 'signed-in', to };
|
|
52
63
|
}
|
|
53
64
|
|
|
54
65
|
function fail(error: unknown) {
|
|
@@ -57,7 +68,7 @@
|
|
|
57
68
|
}
|
|
58
69
|
|
|
59
70
|
async function follow(step: SignInStep) {
|
|
60
|
-
if (step.done) finish();
|
|
71
|
+
if (step.done) await finish();
|
|
61
72
|
else view = { step: 'workspace', workspaces: step.workspaces, choose: step.choose };
|
|
62
73
|
}
|
|
63
74
|
|
|
@@ -69,17 +80,22 @@
|
|
|
69
80
|
view = { step: 'failed', message: t('verify.missingLink'), kind: null };
|
|
70
81
|
return;
|
|
71
82
|
}
|
|
72
|
-
|
|
73
|
-
// The session belongs in the tab that started the sign-up: offer it the link first.
|
|
74
|
-
void offerSignUpLink(config.issuer, found).then((taken) => {
|
|
75
|
-
if (taken) view = { step: 'continued' };
|
|
76
|
-
else getBridge().signUp.finish(found).then(follow, fail);
|
|
77
|
-
});
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
getBridge().signUp.finish(found).then(follow, fail);
|
|
83
|
+
void start(found, relayed !== null);
|
|
81
84
|
});
|
|
82
85
|
|
|
86
|
+
async function start(found: string, relayed: boolean) {
|
|
87
|
+
try {
|
|
88
|
+
// The session belongs in the tab that started the sign-up (memory only): offer it the link first.
|
|
89
|
+
if (!relayed && config?.storage === 'memory' && (await offerSignUpLink(config.issuer, found))) {
|
|
90
|
+
view = { step: 'continued' };
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
await follow(await bounded(getBridge().signUp.finish(found)));
|
|
94
|
+
} catch (error) {
|
|
95
|
+
fail(error);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
83
99
|
async function choose(id: string) {
|
|
84
100
|
if (view.step !== 'workspace') return;
|
|
85
101
|
try {
|
|
@@ -101,6 +117,12 @@
|
|
|
101
117
|
<AuthFormWrapper heading={t('signup.heading')} {headingSnippet} class={className} {style} data-bridge-verify-email="continued" {...rest}>
|
|
102
118
|
<Alert variant="info">{t('verify.continuedElsewhere')}</Alert>
|
|
103
119
|
</AuthFormWrapper>
|
|
120
|
+
{:else if view.step === 'signed-in'}
|
|
121
|
+
<AuthFormWrapper heading={t('signup.heading')} {headingSnippet} class={className} {style} data-bridge-verify-email="signed-in" {...rest}>
|
|
122
|
+
<div class="bridge-form-footer">
|
|
123
|
+
<a href={view.to} class="bridge-link">{t('invite.continue')}</a>
|
|
124
|
+
</div>
|
|
125
|
+
</AuthFormWrapper>
|
|
104
126
|
{:else if view.step === 'workspace'}
|
|
105
127
|
<AuthFormWrapper heading={t('workspace.chooseHeading')} {headingSnippet} class={className} {style} data-bridge-verify-email="workspace" {...rest}>
|
|
106
128
|
<WorkspaceChooser workspaces={view.workspaces} onChoose={choose} {messages} />
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** How long finishing a link may take before the page says it failed. */
|
|
2
|
+
export declare const FINISH_WAIT_MS = 30000;
|
|
3
|
+
/**
|
|
4
|
+
* How many times the page tries to go on once signed in. Signing in makes
|
|
5
|
+
* the route guard run again as the session and the flags settle; SvelteKit
|
|
6
|
+
* lets that newer navigation cancel the one going on.
|
|
7
|
+
*/
|
|
8
|
+
export declare const LEAVE_TRIES = 3;
|
|
9
|
+
/** `work`, or an `unavailable` error when it takes longer than `ms`. */
|
|
10
|
+
export declare function bounded<T>(work: Promise<T>, ms?: number): Promise<T>;
|
|
11
|
+
/**
|
|
12
|
+
* Navigates with `go` until `left` says the page was left: a navigation a
|
|
13
|
+
* newer one cancelled still resolves, so only the address tells. True once
|
|
14
|
+
* left; false after `tries`, and the page offers a link instead.
|
|
15
|
+
*/
|
|
16
|
+
export declare function leave(go: () => Promise<unknown>, left: () => boolean, tries?: number): Promise<boolean>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bounds for the page that finishes a sign-up from its email link, so it
|
|
3
|
+
* never waits without end: finishing has a time limit, and once signed in
|
|
4
|
+
* the page goes on even when another navigation cancels its first try.
|
|
5
|
+
*/
|
|
6
|
+
import { BridgeError } from '@nebulr-group/bridge-auth-core';
|
|
7
|
+
/** How long finishing a link may take before the page says it failed. */
|
|
8
|
+
export const FINISH_WAIT_MS = 30_000;
|
|
9
|
+
/**
|
|
10
|
+
* How many times the page tries to go on once signed in. Signing in makes
|
|
11
|
+
* the route guard run again as the session and the flags settle; SvelteKit
|
|
12
|
+
* lets that newer navigation cancel the one going on.
|
|
13
|
+
*/
|
|
14
|
+
export const LEAVE_TRIES = 3;
|
|
15
|
+
/** `work`, or an `unavailable` error when it takes longer than `ms`. */
|
|
16
|
+
export function bounded(work, ms = FINISH_WAIT_MS) {
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
const timer = setTimeout(() => reject(new BridgeError('unavailable', 'Finishing the link took too long.')), ms);
|
|
19
|
+
work.then((value) => {
|
|
20
|
+
clearTimeout(timer);
|
|
21
|
+
resolve(value);
|
|
22
|
+
}, (error) => {
|
|
23
|
+
clearTimeout(timer);
|
|
24
|
+
reject(error);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Navigates with `go` until `left` says the page was left: a navigation a
|
|
30
|
+
* newer one cancelled still resolves, so only the address tells. True once
|
|
31
|
+
* left; false after `tries`, and the page offers a link instead.
|
|
32
|
+
*/
|
|
33
|
+
export async function leave(go, left, tries = LEAVE_TRIES) {
|
|
34
|
+
for (let tried = 0; tried < tries; tried += 1) {
|
|
35
|
+
try {
|
|
36
|
+
await go();
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
// A failed navigation is tried again like a cancelled one.
|
|
40
|
+
}
|
|
41
|
+
if (left())
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}
|
package/dist/core/messages.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* impersonal errors that end in a full stop, labels and buttons without one,
|
|
5
5
|
* placeholders positioned in the sentence.
|
|
6
6
|
*/
|
|
7
|
-
export type PluginMessageKey = 'signup.closed' | 'field.workspaceName' | 'verify.missingLink' | 'forgot.setDone' | 'invite.description' | 'invite.notOffered' | 'invite.signInToAccept' | 'invite.signUpToAccept' | 'invite.signedInAs' | 'invite.continue' | 'invite.state.revoked' | 'invite.state.used' | 'invite.state.expired' | 'invite.wrongAddress' | 'invite.alreadyMember' | 'invite.accountExists' | 'verify.continuedElsewhere' | 'handoff.invalid' | 'handoff.notOffered' | 'session.ended' | 'session.accessRemoved' | 'error.generic' | 'workspace.empty' | 'workspace.current' | 'password.tooShort' | 'feature.upgrade';
|
|
7
|
+
export type PluginMessageKey = 'signup.closed' | 'field.workspaceName' | 'verify.missingLink' | 'forgot.setDone' | 'invite.description' | 'invite.notOffered' | 'invite.signInToAccept' | 'invite.signUpToAccept' | 'invite.signedInAs' | 'invite.continue' | 'invite.state.revoked' | 'invite.state.used' | 'invite.state.expired' | 'invite.wrongAddress' | 'invite.alreadyMember' | 'invite.accountExists' | 'verify.continuedElsewhere' | 'handoff.invalid' | 'handoff.notOffered' | 'session.ended' | 'session.accessRemoved' | 'error.generic' | 'workspace.empty' | 'workspace.current' | 'password.tooShort' | 'feature.upgrade' | 'magicLink.send' | 'magicLink.sent' | 'magicLink.finishing' | 'magicLink.wrongDevice' | 'magicLink.or';
|
|
8
8
|
export type PluginMessages = Record<PluginMessageKey, string>;
|
|
9
9
|
/** The plugin's copy by primary language subtag. */
|
|
10
10
|
export declare const PLUGIN_LOCALES: Readonly<Record<string, PluginMessages>>;
|
package/dist/core/messages.js
CHANGED
|
@@ -25,6 +25,11 @@ const en = {
|
|
|
25
25
|
'workspace.current': 'Current',
|
|
26
26
|
'password.tooShort': 'Use at least {count} characters.',
|
|
27
27
|
'feature.upgrade': 'Upgrade to use this',
|
|
28
|
+
'magicLink.send': 'Email me a sign-in link',
|
|
29
|
+
'magicLink.sent': 'If this address has an account, a sign-in link is on its way. Open it on this device.',
|
|
30
|
+
'magicLink.finishing': 'Signing you in…',
|
|
31
|
+
'magicLink.wrongDevice': 'Open the link on the device where you asked for it.',
|
|
32
|
+
'magicLink.or': 'or',
|
|
28
33
|
};
|
|
29
34
|
const sv = {
|
|
30
35
|
'signup.closed': 'Registrering är stängd för den här appen.',
|
|
@@ -53,6 +58,11 @@ const sv = {
|
|
|
53
58
|
'workspace.current': 'Aktuell',
|
|
54
59
|
'password.tooShort': 'Använd minst {count} tecken.',
|
|
55
60
|
'feature.upgrade': 'Uppgradera för att använda detta',
|
|
61
|
+
'magicLink.send': 'Mejla mig en inloggningslänk',
|
|
62
|
+
'magicLink.sent': 'Om adressen har ett konto är en inloggningslänk på väg. Öppna den på den här enheten.',
|
|
63
|
+
'magicLink.finishing': 'Loggar in dig…',
|
|
64
|
+
'magicLink.wrongDevice': 'Öppna länken på enheten där du bad om den.',
|
|
65
|
+
'magicLink.or': 'eller',
|
|
56
66
|
};
|
|
57
67
|
const da = {
|
|
58
68
|
'signup.closed': 'Tilmelding er lukket for denne app.',
|
|
@@ -81,6 +91,11 @@ const da = {
|
|
|
81
91
|
'workspace.current': 'Aktuel',
|
|
82
92
|
'password.tooShort': 'Brug mindst {count} tegn.',
|
|
83
93
|
'feature.upgrade': 'Opgrader for at bruge dette',
|
|
94
|
+
'magicLink.send': 'Send mig et login-link',
|
|
95
|
+
'magicLink.sent': 'Hvis adressen har en konto, er et login-link på vej. Åbn det på denne enhed.',
|
|
96
|
+
'magicLink.finishing': 'Logger dig ind…',
|
|
97
|
+
'magicLink.wrongDevice': 'Åbn linket på den enhed, hvor du bad om det.',
|
|
98
|
+
'magicLink.or': 'eller',
|
|
84
99
|
};
|
|
85
100
|
const nb = {
|
|
86
101
|
'signup.closed': 'Registrering er stengt for denne appen.',
|
|
@@ -109,6 +124,11 @@ const nb = {
|
|
|
109
124
|
'workspace.current': 'Gjeldende',
|
|
110
125
|
'password.tooShort': 'Bruk minst {count} tegn.',
|
|
111
126
|
'feature.upgrade': 'Oppgrader for å bruke dette',
|
|
127
|
+
'magicLink.send': 'Send meg en innloggingslenke',
|
|
128
|
+
'magicLink.sent': 'Hvis adressen har en konto, er en innloggingslenke på vei. Åpne den på denne enheten.',
|
|
129
|
+
'magicLink.finishing': 'Logger deg inn…',
|
|
130
|
+
'magicLink.wrongDevice': 'Åpne lenken på enheten der du ba om den.',
|
|
131
|
+
'magicLink.or': 'eller',
|
|
112
132
|
};
|
|
113
133
|
const nl = {
|
|
114
134
|
'signup.closed': 'Registreren is gesloten voor deze app.',
|
|
@@ -137,6 +157,11 @@ const nl = {
|
|
|
137
157
|
'workspace.current': 'Huidig',
|
|
138
158
|
'password.tooShort': 'Gebruik minstens {count} tekens.',
|
|
139
159
|
'feature.upgrade': 'Upgrade om dit te gebruiken',
|
|
160
|
+
'magicLink.send': 'Mail me een inloglink',
|
|
161
|
+
'magicLink.sent': 'Als dit adres een account heeft, is er een inloglink onderweg. Open hem op dit apparaat.',
|
|
162
|
+
'magicLink.finishing': 'Je wordt ingelogd…',
|
|
163
|
+
'magicLink.wrongDevice': 'Open de link op het apparaat waarop je hem hebt aangevraagd.',
|
|
164
|
+
'magicLink.or': 'of',
|
|
140
165
|
};
|
|
141
166
|
const de = {
|
|
142
167
|
'signup.closed': 'Die Registrierung ist für diese App geschlossen.',
|
|
@@ -165,6 +190,11 @@ const de = {
|
|
|
165
190
|
'workspace.current': 'Aktuell',
|
|
166
191
|
'password.tooShort': 'Verwende mindestens {count} Zeichen.',
|
|
167
192
|
'feature.upgrade': 'Upgrade, um das zu nutzen',
|
|
193
|
+
'magicLink.send': 'Schick mir einen Anmeldelink',
|
|
194
|
+
'magicLink.sent': 'Wenn diese Adresse ein Konto hat, ist ein Anmeldelink unterwegs. Öffne ihn auf diesem Gerät.',
|
|
195
|
+
'magicLink.finishing': 'Du wirst angemeldet…',
|
|
196
|
+
'magicLink.wrongDevice': 'Öffne den Link auf dem Gerät, auf dem du ihn angefordert hast.',
|
|
197
|
+
'magicLink.or': 'oder',
|
|
168
198
|
};
|
|
169
199
|
const fi = {
|
|
170
200
|
'signup.closed': 'Rekisteröityminen on suljettu tässä sovelluksessa.',
|
|
@@ -193,6 +223,11 @@ const fi = {
|
|
|
193
223
|
'workspace.current': 'Nykyinen',
|
|
194
224
|
'password.tooShort': 'Käytä vähintään {count} merkkiä.',
|
|
195
225
|
'feature.upgrade': 'Päivitä käyttääksesi tätä',
|
|
226
|
+
'magicLink.send': 'Lähetä minulle kirjautumislinkki',
|
|
227
|
+
'magicLink.sent': 'Jos osoitteella on tili, kirjautumislinkki on matkalla. Avaa se tällä laitteella.',
|
|
228
|
+
'magicLink.finishing': 'Kirjaudutaan sisään…',
|
|
229
|
+
'magicLink.wrongDevice': 'Avaa linkki laitteella, jolla pyysit sitä.',
|
|
230
|
+
'magicLink.or': 'tai',
|
|
196
231
|
};
|
|
197
232
|
const fr = {
|
|
198
233
|
'signup.closed': 'Les inscriptions sont fermées pour cette application.',
|
|
@@ -221,6 +256,11 @@ const fr = {
|
|
|
221
256
|
'workspace.current': 'Actuel',
|
|
222
257
|
'password.tooShort': 'Utilise au moins {count} caractères.',
|
|
223
258
|
'feature.upgrade': 'Passe à l\'offre supérieure pour l\'utiliser',
|
|
259
|
+
'magicLink.send': 'Envoie-moi un lien de connexion',
|
|
260
|
+
'magicLink.sent': 'Si cette adresse a un compte, un lien de connexion est en route. Ouvre-le sur cet appareil.',
|
|
261
|
+
'magicLink.finishing': 'Connexion en cours…',
|
|
262
|
+
'magicLink.wrongDevice': 'Ouvre le lien sur l\'appareil où tu l\'as demandé.',
|
|
263
|
+
'magicLink.or': 'ou',
|
|
224
264
|
};
|
|
225
265
|
const es = {
|
|
226
266
|
'signup.closed': 'El registro está cerrado para esta aplicación.',
|
|
@@ -249,6 +289,11 @@ const es = {
|
|
|
249
289
|
'workspace.current': 'Actual',
|
|
250
290
|
'password.tooShort': 'Usa al menos {count} caracteres.',
|
|
251
291
|
'feature.upgrade': 'Mejora tu plan para usar esto',
|
|
292
|
+
'magicLink.send': 'Envíame un enlace para iniciar sesión',
|
|
293
|
+
'magicLink.sent': 'Si esta dirección tiene una cuenta, hay un enlace para iniciar sesión en camino. Ábrelo en este dispositivo.',
|
|
294
|
+
'magicLink.finishing': 'Iniciando sesión…',
|
|
295
|
+
'magicLink.wrongDevice': 'Abre el enlace en el dispositivo donde lo pediste.',
|
|
296
|
+
'magicLink.or': 'o',
|
|
252
297
|
};
|
|
253
298
|
const it = {
|
|
254
299
|
'signup.closed': 'La registrazione è chiusa per questa app.',
|
|
@@ -277,6 +322,11 @@ const it = {
|
|
|
277
322
|
'workspace.current': 'Attuale',
|
|
278
323
|
'password.tooShort': 'Usa almeno {count} caratteri.',
|
|
279
324
|
'feature.upgrade': 'Passa a un piano superiore per usarlo',
|
|
325
|
+
'magicLink.send': 'Inviami un link di accesso',
|
|
326
|
+
'magicLink.sent': 'Se questo indirizzo ha un account, un link di accesso è in arrivo. Aprilo su questo dispositivo.',
|
|
327
|
+
'magicLink.finishing': 'Accesso in corso…',
|
|
328
|
+
'magicLink.wrongDevice': 'Apri il link sul dispositivo da cui l\'hai richiesto.',
|
|
329
|
+
'magicLink.or': 'oppure',
|
|
280
330
|
};
|
|
281
331
|
const pt = {
|
|
282
332
|
'signup.closed': 'O registo está fechado para esta aplicação.',
|
|
@@ -305,6 +355,11 @@ const pt = {
|
|
|
305
355
|
'workspace.current': 'Atual',
|
|
306
356
|
'password.tooShort': 'Usa pelo menos {count} caracteres.',
|
|
307
357
|
'feature.upgrade': 'Faz upgrade para usar isto',
|
|
358
|
+
'magicLink.send': 'Envia-me um link para iniciar sessão',
|
|
359
|
+
'magicLink.sent': 'Se este endereço tiver uma conta, um link para iniciar sessão está a caminho. Abre-o neste dispositivo.',
|
|
360
|
+
'magicLink.finishing': 'A iniciar sessão…',
|
|
361
|
+
'magicLink.wrongDevice': 'Abre o link no dispositivo onde o pediste.',
|
|
362
|
+
'magicLink.or': 'ou',
|
|
308
363
|
};
|
|
309
364
|
const pl = {
|
|
310
365
|
'signup.closed': 'Rejestracja w tej aplikacji jest zamknięta.',
|
|
@@ -333,6 +388,11 @@ const pl = {
|
|
|
333
388
|
'workspace.current': 'Bieżąca',
|
|
334
389
|
'password.tooShort': 'Użyj co najmniej {count} znaków.',
|
|
335
390
|
'feature.upgrade': 'Zmień plan, by z tego korzystać',
|
|
391
|
+
'magicLink.send': 'Wyślij mi link do logowania',
|
|
392
|
+
'magicLink.sent': 'Jeśli ten adres ma konto, link do logowania jest w drodze. Otwórz go na tym urządzeniu.',
|
|
393
|
+
'magicLink.finishing': 'Logowanie…',
|
|
394
|
+
'magicLink.wrongDevice': 'Otwórz link na urządzeniu, na którym o niego poproszono.',
|
|
395
|
+
'magicLink.or': 'lub',
|
|
336
396
|
};
|
|
337
397
|
/** The plugin's copy by primary language subtag. */
|
|
338
398
|
export const PLUGIN_LOCALES = { da, de, en, es, fi, fr, it, nb, nl, pl, pt, sv };
|
package/dist/core/routes.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* list, so no page an email links to can be forgotten.
|
|
6
6
|
*/
|
|
7
7
|
import type { EmailLink } from '@nebulr-group/bridge-auth-core';
|
|
8
|
-
export declare const AUTH_PAGES: readonly ["sign-in", "sign-up", "verify-email", "forgot-password", "set-password", "invite", "workspaces", "handoff"];
|
|
8
|
+
export declare const AUTH_PAGES: readonly ["sign-in", "sign-up", "verify-email", "forgot-password", "set-password", "invite", "workspaces", "handoff", "magic-link"];
|
|
9
9
|
export type AuthPage = (typeof AUTH_PAGES)[number];
|
|
10
10
|
export declare const BILLING_PAGES: readonly ["manage", "plan", "success", "error"];
|
|
11
11
|
export type BillingPage = (typeof BILLING_PAGES)[number];
|
package/dist/core/routes.js
CHANGED
|
@@ -7,6 +7,7 @@ export const AUTH_PAGES = [
|
|
|
7
7
|
'invite',
|
|
8
8
|
'workspaces',
|
|
9
9
|
'handoff',
|
|
10
|
+
'magic-link',
|
|
10
11
|
];
|
|
11
12
|
export const BILLING_PAGES = ['manage', 'plan', 'success', 'error'];
|
|
12
13
|
/** The catch-all parameter's name: `[...bridge]`. */
|
|
@@ -40,6 +41,8 @@ export function pageForLink(link) {
|
|
|
40
41
|
return 'set-password';
|
|
41
42
|
case 'invite':
|
|
42
43
|
return 'invite';
|
|
44
|
+
case 'magic-link':
|
|
45
|
+
return 'magic-link';
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
48
|
/** Whether `path` is `base` or under it. */
|
package/dist/index.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ export { default as BridgeAuthRoutes } from './components/auth/BridgeAuthRoutes.
|
|
|
32
32
|
export { default as SignInForm } from './components/auth/SignInForm.svelte';
|
|
33
33
|
export { default as SignUpForm } from './components/auth/SignUpForm.svelte';
|
|
34
34
|
export { default as VerifyEmail } from './components/auth/VerifyEmail.svelte';
|
|
35
|
+
export { default as MagicLinkLanding } from './components/auth/MagicLinkLanding.svelte';
|
|
35
36
|
export { default as ForgotPassword } from './components/auth/ForgotPassword.svelte';
|
|
36
37
|
export { default as SetPassword } from './components/auth/SetPassword.svelte';
|
|
37
38
|
export { default as InviteLanding } from './components/auth/InviteLanding.svelte';
|
package/dist/index.js
CHANGED
|
@@ -30,6 +30,7 @@ export { default as BridgeAuthRoutes } from './components/auth/BridgeAuthRoutes.
|
|
|
30
30
|
export { default as SignInForm } from './components/auth/SignInForm.svelte';
|
|
31
31
|
export { default as SignUpForm } from './components/auth/SignUpForm.svelte';
|
|
32
32
|
export { default as VerifyEmail } from './components/auth/VerifyEmail.svelte';
|
|
33
|
+
export { default as MagicLinkLanding } from './components/auth/MagicLinkLanding.svelte';
|
|
33
34
|
export { default as ForgotPassword } from './components/auth/ForgotPassword.svelte';
|
|
34
35
|
export { default as SetPassword } from './components/auth/SetPassword.svelte';
|
|
35
36
|
export { default as InviteLanding } from './components/auth/InviteLanding.svelte';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nebulr-group/bridge-svelte",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.4",
|
|
4
4
|
"description": "The Bridge for SvelteKit: sign-in in your own pages, workspaces, flag-based route guards, plans and checkout, the team panel and live updates, on one setting: the issuer.",
|
|
5
5
|
"author": "Iman Pouya",
|
|
6
6
|
"license": "MIT",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"@sveltejs/kit": "^2.0.0"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@nebulr-group/bridge-auth-core": "1.0.0-alpha.
|
|
63
|
+
"@nebulr-group/bridge-auth-core": "1.0.0-alpha.4"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@sveltejs/kit": "^2.16.0",
|