@axium/client 0.41.0 → 0.42.1

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/user.d.ts CHANGED
@@ -7,6 +7,8 @@ export declare function login(userId: string): Promise<NewSessionResponse>;
7
7
  */
8
8
  export declare function elevate(userId: string): Promise<void>;
9
9
  export declare function loginByUsername(username: string): Promise<NewSessionResponse>;
10
+ /** Resolves once the user picks a passkey from the browser's autofill on an `autocomplete="webauthn"` input. */
11
+ export declare function loginWithAutofill(): Promise<NewSessionResponse>;
10
12
  export declare function getCurrentSession(): Promise<Session & {
11
13
  user: User;
12
14
  }>;
package/dist/user.js CHANGED
@@ -21,6 +21,12 @@ export async function loginByUsername(username) {
21
21
  const { id: userId } = await fetchAPI('POST', 'user_id', { using: 'username', value: username });
22
22
  return await login(userId);
23
23
  }
24
+ /** Resolves once the user picks a passkey from the browser's autofill on an `autocomplete="webauthn"` input. */
25
+ export async function loginWithAutofill() {
26
+ const optionsJSON = await fetchAPI('OPTIONS', 'login');
27
+ const response = await startAuthentication({ optionsJSON, useBrowserAutofill: true });
28
+ return await fetchAPI('POST', 'login', response);
29
+ }
24
30
  let _currentSession = null;
25
31
  export async function getCurrentSession() {
26
32
  _currentSession ||= await fetchAPI('GET', 'session');
package/lib/Login.svelte CHANGED
@@ -1,10 +1,27 @@
1
1
  <script lang="ts">
2
- import { loginByUsername, text } from '@axium/client';
2
+ import { loginByUsername, loginWithAutofill, text } from '@axium/client';
3
+ import { browserSupportsWebAuthnAutofill } from '@simplewebauthn/browser';
4
+ import { onMount } from 'svelte';
3
5
  import FormDialog from './FormDialog.svelte';
4
6
  import authRedirect from './auth_redirect.js';
5
7
 
6
8
  let { dialog = $bindable(), fullPage = false }: { dialog?: HTMLDialogElement; fullPage?: boolean } = $props();
7
9
 
10
+ onMount(async () => {
11
+ if (!(await browserSupportsWebAuthnAutofill())) return;
12
+
13
+ try {
14
+ await loginWithAutofill();
15
+ } catch (error: any) {
16
+ // Starting another WebAuthn ceremony, such as submitting the form, aborts this one.
17
+ if (error?.code != 'ERROR_CEREMONY_ABORTED') console.error(error);
18
+ return;
19
+ }
20
+
21
+ if (!fullPage) dialog?.close();
22
+ await authRedirect();
23
+ });
24
+
8
25
  async function submit(data: { username: string }) {
9
26
  if (typeof data.username != 'string') {
10
27
  throw 'Tried to upload a file for a username. Huh?!';
@@ -19,7 +36,7 @@
19
36
  <FormDialog bind:dialog submitText={text('generic.login')} {submit} pageMode={fullPage}>
20
37
  <div>
21
38
  <label for="username">{text('generic.username')}</label>
22
- <input name="username" type="text" required />
39
+ <input name="username" type="text" autocomplete="username webauthn" required />
23
40
  </div>
24
41
  {#snippet footer()}
25
42
  {#if fullPage}
@@ -0,0 +1,52 @@
1
+ <script lang="ts">
2
+ /** From 0 to 1. Without a finite number, the ring spins instead. */
3
+ const { value }: { value?: number | null } = $props();
4
+
5
+ const measured = $derived(typeof value == 'number' && Number.isFinite(value));
6
+ </script>
7
+
8
+ <svg
9
+ class={['ProgressRing', !measured && 'indeterminate']}
10
+ viewBox="0 0 20 20"
11
+ role="progressbar"
12
+ aria-valuenow={measured ? Math.round(value! * 100) : undefined}
13
+ aria-valuemin={0}
14
+ aria-valuemax={100}
15
+ >
16
+ <circle class="track" cx="10" cy="10" r="8" />
17
+ <circle class="fill" cx="10" cy="10" r="8" pathLength="100" stroke-dasharray="{measured ? value! * 100 : 25} 100" />
18
+ </svg>
19
+
20
+ <style>
21
+ .ProgressRing {
22
+ width: var(--size, 1em);
23
+ height: var(--size, 1em);
24
+ flex-shrink: 0;
25
+ rotate: -90deg;
26
+ }
27
+
28
+ circle {
29
+ fill: none;
30
+ stroke-width: 3;
31
+ }
32
+
33
+ .track {
34
+ stroke: var(--bg-strong);
35
+ }
36
+
37
+ .fill {
38
+ stroke: var(--fg-accent);
39
+ stroke-linecap: round;
40
+ transition: stroke-dasharray 0.5s;
41
+ }
42
+
43
+ .indeterminate {
44
+ animation: spin 1s linear infinite;
45
+ }
46
+
47
+ @keyframes spin {
48
+ to {
49
+ rotate: 270deg;
50
+ }
51
+ }
52
+ </style>
package/lib/index.ts CHANGED
@@ -18,6 +18,7 @@ export { default as Logout } from './Logout.svelte';
18
18
  export { default as MediaControls } from './MediaControls.svelte';
19
19
  export { default as NumberBar } from './NumberBar.svelte';
20
20
  export { default as Popover } from './Popover.svelte';
21
+ export { default as ProgressRing } from './ProgressRing.svelte';
21
22
  export { default as PWAIndicator } from './PWAIndicator.svelte';
22
23
  export { default as Register } from './Register.svelte';
23
24
  export { default as SessionList } from './SessionList.svelte';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/client",
3
- "version": "0.41.0",
3
+ "version": "0.42.1",
4
4
  "author": "James Prevett <jp@jamespre.dev>",
5
5
  "funding": {
6
6
  "type": "individual",