@useauthio/react 0.2.2 → 0.2.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/CHANGELOG.md +31 -0
- package/README.md +61 -4
- package/dist/index.cjs +434 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +120 -2
- package/dist/index.d.ts +120 -2
- package/dist/index.js +425 -17
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
- package/src/PasskeyManager.tsx +164 -0
- package/src/index.ts +24 -0
- package/src/lobby-context.ts +63 -0
- package/src/passkeys.ts +247 -0
- package/src/provider.tsx +23 -15
- package/src/types.ts +9 -1
- package/src/usePasskeys.ts +134 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,37 @@ All notable changes to `@useauthio/react` are documented here. This
|
|
|
4
4
|
project adheres to [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
|
|
5
5
|
and [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [0.2.4] — 2026-06-19
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- **Passkey management for customer apps.** `listPasskeys`, `renamePasskey`,
|
|
11
|
+
`revokePasskey`, `mintPasskeyRegisterIntent`, `buildEnrollPasskeyUrl`, and
|
|
12
|
+
`enrollPasskey` helpers for `/v1/me/passkeys` and hosted-UI
|
|
13
|
+
`mode=add_credential` enrollment.
|
|
14
|
+
- **`usePasskeys` hook** and **`<PasskeyManager />`** drop-in component for
|
|
15
|
+
in-app device lists (list/rename/revoke on your origin; add via redirect to
|
|
16
|
+
the sign-in host).
|
|
17
|
+
- **`addPasskey()`** for embedded WebAuthn enrollment when your SPA shares
|
|
18
|
+
the sign-in origin (`canEnrollPasskeyEmbedded`).
|
|
19
|
+
|
|
20
|
+
## [0.2.3] — 2026-06-17
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
- **Signed lobby context tokens.** `signIn()` now POSTs to
|
|
24
|
+
`/v1/auth/lobby-context` and redirects with a short-lived `?ctx=…`
|
|
25
|
+
param when auth-core supports it, so `project_id` and `redirect_uri`
|
|
26
|
+
are not exposed in the browser URL. Falls back to legacy query params
|
|
27
|
+
when minting fails or auth-core is unavailable.
|
|
28
|
+
- **Environment terminology in docs.** README documents `projectId` as
|
|
29
|
+
the dashboard **environment ID** (`proj_…`; API field `project_id`).
|
|
30
|
+
Env var names (`AUTHIO_PROJECT_ID`, `VITE_AUTHIO_PROJECT_ID`) are
|
|
31
|
+
unchanged for backward compatibility.
|
|
32
|
+
|
|
33
|
+
### Changed
|
|
34
|
+
- README adds custom-domain guidance: keep the default Lobby URL at
|
|
35
|
+
runtime, override `signInUrl` / `VITE_AUTHIO_SIGN_IN_URL` for branded
|
|
36
|
+
auth hosts; DNS CNAME target is `cname.authiodns.com` (docs-only).
|
|
37
|
+
|
|
7
38
|
## [0.2.2] — 2026-06-13
|
|
8
39
|
|
|
9
40
|
### Fixed
|
package/README.md
CHANGED
|
@@ -133,6 +133,27 @@ auth-core JWKS before trusting it.
|
|
|
133
133
|
|
|
134
134
|
A complete runnable example lives in [`examples/vite-react/`](./examples/vite-react/).
|
|
135
135
|
|
|
136
|
+
### Custom auth domains
|
|
137
|
+
|
|
138
|
+
The default `signInUrl` is the platform Lobby (`https://lobby.authio.com/`).
|
|
139
|
+
Enterprise customers with a branded auth host point `signInUrl` at that URL
|
|
140
|
+
instead — in Vite apps, typically via `VITE_AUTHIO_SIGN_IN_URL`:
|
|
141
|
+
|
|
142
|
+
```tsx
|
|
143
|
+
<AuthioProvider
|
|
144
|
+
apiUrl={import.meta.env.VITE_AUTHIO_API_URL}
|
|
145
|
+
projectId={import.meta.env.VITE_AUTHIO_PROJECT_ID}
|
|
146
|
+
signInUrl={
|
|
147
|
+
import.meta.env.VITE_AUTHIO_SIGN_IN_URL ?? "https://lobby.authio.com/"
|
|
148
|
+
}
|
|
149
|
+
/>
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
DNS setup for a vanity hostname (e.g. `auth.acme.com`) is dashboard-side:
|
|
153
|
+
CNAME your auth host to **`cname.authiodns.com`**. The SDK does not reference
|
|
154
|
+
that CNAME at runtime — it only affects where end users sign in when you override
|
|
155
|
+
`signInUrl`. See [Custom domains](https://docs.authio.com/guides/custom-domains).
|
|
156
|
+
|
|
136
157
|
---
|
|
137
158
|
|
|
138
159
|
## API reference
|
|
@@ -142,12 +163,12 @@ A complete runnable example lives in [`examples/vite-react/`](./examples/vite-re
|
|
|
142
163
|
| Prop | Type | Default | Description |
|
|
143
164
|
|------|------|---------|-------------|
|
|
144
165
|
| `apiUrl` | `string` (required) | — | Auth-core base URL, e.g. `"https://auth-api.authio.com"`. |
|
|
145
|
-
| `projectId` | `string` (required) | — |
|
|
166
|
+
| `projectId` | `string` (required) | — | Environment ID (`proj_…`; API field `project_id`). Sent as `X-Authio-Project` on every call. |
|
|
146
167
|
| `storage` | `"memory" \| "localStorage" \| "sessionStorage" \| "none"` | `"memory"` | Access-token storage backend. **Refresh tokens are never JS-accessible** regardless of this setting. |
|
|
147
168
|
| `refreshLeadSeconds` | `number` | `60` | How many seconds before `exp` to schedule the silent refresh. |
|
|
148
169
|
| `onTelemetryEvent` | `(event: AuthioTelemetryEvent) => void` | — | Sink for SDK telemetry (refresh outcomes, sign-in starts/completes, token verification). No phone-home by default. |
|
|
149
170
|
| `fetch` | `typeof fetch` | `globalThis.fetch` | DI for tests / custom transports. |
|
|
150
|
-
| `signInUrl` | `string` | `https://lobby.authio.com/` | Lobby (hosted UI) sign-in URL. |
|
|
171
|
+
| `signInUrl` | `string` | `https://lobby.authio.com/` | Lobby (hosted UI) sign-in URL. Set to your branded auth host (e.g. `https://auth.acme.com/`) when using a custom domain — see [Custom auth domains](#custom-auth-domains) below. |
|
|
151
172
|
| `jwtIssuer` | `string` | `apiUrl` | JWT `iss` claim to require during verification. |
|
|
152
173
|
| `jwtAudience` | `string` | `"authio"` | JWT `aud` claim to require during verification. |
|
|
153
174
|
| `verifyToken` | `AuthioTokenVerifier` | `JwtVerifier`-based | Override the verification step (testing / custom JWKS). |
|
|
@@ -171,8 +192,10 @@ A complete runnable example lives in [`examples/vite-react/`](./examples/vite-re
|
|
|
171
192
|
from `exp`, otherwise transparently triggers a refresh and returns
|
|
172
193
|
the new value (or `null` on failure). Use it as your `Authorization`
|
|
173
194
|
source for outbound API calls.
|
|
174
|
-
- `signIn()` navigates the tab to Lobby (`signInUrl`)
|
|
175
|
-
|
|
195
|
+
- `signIn()` navigates the tab to Lobby (`signInUrl`). When auth-core
|
|
196
|
+
supports it, the SDK mints a short-lived `ctx` token so
|
|
197
|
+
`project_id` and `redirect_uri` are not exposed in the URL; it falls
|
|
198
|
+
back to legacy `?project_id=…&redirect_uri=…` query params otherwise.
|
|
176
199
|
- `signOut()` best-effort POSTs to `/v1/auth/sign-out`, then clears
|
|
177
200
|
local state regardless of the upstream result.
|
|
178
201
|
- `refresh()` runs one refresh attempt and resolves `true` on success.
|
|
@@ -222,6 +245,40 @@ The returned `refreshToken` is included for completeness but the SDK
|
|
|
222
245
|
itself never persists it — auth-core also sets the refresh cookie via
|
|
223
246
|
`Set-Cookie` and that's the canonical home for it.
|
|
224
247
|
|
|
248
|
+
### Passkey management (`/v1/me/passkeys`)
|
|
249
|
+
|
|
250
|
+
After signup, let users add and manage passkeys on the sign-in origin
|
|
251
|
+
or from your SPA:
|
|
252
|
+
|
|
253
|
+
```ts
|
|
254
|
+
import {
|
|
255
|
+
addPasskey,
|
|
256
|
+
listPasskeys,
|
|
257
|
+
renamePasskey,
|
|
258
|
+
revokePasskey,
|
|
259
|
+
enrollPasskey,
|
|
260
|
+
usePasskeys,
|
|
261
|
+
PasskeyManager,
|
|
262
|
+
} from "@useauthio/react";
|
|
263
|
+
|
|
264
|
+
const token = await getAccessToken();
|
|
265
|
+
await addPasskey({
|
|
266
|
+
apiUrl: "https://auth-api.authio.com",
|
|
267
|
+
projectId: "proj_123",
|
|
268
|
+
accessToken: token!,
|
|
269
|
+
email: user.email!,
|
|
270
|
+
});
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
- `addPasskey` — inline WebAuthn on the **current origin** (use when
|
|
274
|
+
your app runs on the same host as the hosted sign-in UI / custom
|
|
275
|
+
`auth.` domain).
|
|
276
|
+
- `enrollPasskey` — redirects to hosted UI `?mode=add_credential` when
|
|
277
|
+
the SPA origin differs from the WebAuthn RP ID.
|
|
278
|
+
- `listPasskeys` / `renamePasskey` / `revokePasskey` — CRUD against
|
|
279
|
+
`/v1/me/passkeys` with a session `accessToken`.
|
|
280
|
+
- `<PasskeyManager />` + `usePasskeys()` — drop-in UI for customer apps.
|
|
281
|
+
|
|
225
282
|
### `AuthioError`
|
|
226
283
|
|
|
227
284
|
Re-exported from `@useauthio/node`. Thrown by every helper and the
|
package/dist/index.cjs
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var react = require('react');
|
|
4
4
|
var node = require('@useauthio/node');
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
var browser = require('@simplewebauthn/browser');
|
|
6
7
|
|
|
7
8
|
// src/provider.tsx
|
|
8
9
|
function wrapFetchError(err, fallbackCode = "network_error") {
|
|
@@ -287,6 +288,49 @@ function createTokenStorage(mode = "memory") {
|
|
|
287
288
|
return new MemoryStorage();
|
|
288
289
|
}
|
|
289
290
|
|
|
291
|
+
// src/lobby-context.ts
|
|
292
|
+
async function mintLobbySignInUrl(opts) {
|
|
293
|
+
const target = new URL(opts.hostedUiUrl.replace(/\/$/, "") + "/");
|
|
294
|
+
if (opts.projectId) {
|
|
295
|
+
try {
|
|
296
|
+
const fetchImpl = opts.fetchImpl ?? globalThis.fetch.bind(globalThis);
|
|
297
|
+
const res = await fetchImpl(
|
|
298
|
+
`${opts.apiUrl.replace(/\/$/, "")}/v1/auth/lobby-context`,
|
|
299
|
+
{
|
|
300
|
+
method: "POST",
|
|
301
|
+
headers: {
|
|
302
|
+
Accept: "application/json",
|
|
303
|
+
"Content-Type": "application/json",
|
|
304
|
+
"X-Authio-Project": opts.projectId,
|
|
305
|
+
"X-Authio-SDK": SDK_USER_AGENT
|
|
306
|
+
},
|
|
307
|
+
body: JSON.stringify({
|
|
308
|
+
project_id: opts.projectId,
|
|
309
|
+
redirect_uri: opts.redirectUri,
|
|
310
|
+
...opts.next ? { next: opts.next } : {}
|
|
311
|
+
})
|
|
312
|
+
}
|
|
313
|
+
);
|
|
314
|
+
if (res.ok) {
|
|
315
|
+
const body = await res.json();
|
|
316
|
+
if (typeof body.ctx === "string" && body.ctx.trim()) {
|
|
317
|
+
target.searchParams.set("ctx", body.ctx.trim());
|
|
318
|
+
return target.toString();
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
} catch {
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (opts.projectId) {
|
|
325
|
+
target.searchParams.set("project_id", opts.projectId);
|
|
326
|
+
}
|
|
327
|
+
target.searchParams.set("redirect_uri", opts.redirectUri);
|
|
328
|
+
if (opts.next) {
|
|
329
|
+
target.searchParams.set("next", opts.next);
|
|
330
|
+
}
|
|
331
|
+
return target.toString();
|
|
332
|
+
}
|
|
333
|
+
|
|
290
334
|
// src/telemetry.ts
|
|
291
335
|
var noopEmitter = () => {
|
|
292
336
|
};
|
|
@@ -524,8 +568,8 @@ function AuthioProvider(props) {
|
|
|
524
568
|
const ok = await performRefresh();
|
|
525
569
|
return ok ? storageRef.current.get() : null;
|
|
526
570
|
}, [accessToken, performRefresh]);
|
|
527
|
-
const signIn = react.useCallback(
|
|
528
|
-
(
|
|
571
|
+
const signIn = react.useCallback((opts = {}) => {
|
|
572
|
+
void (async () => {
|
|
529
573
|
const p = propsRef.current;
|
|
530
574
|
p.emit({
|
|
531
575
|
kind: "sign_in_started",
|
|
@@ -538,19 +582,16 @@ function AuthioProvider(props) {
|
|
|
538
582
|
'[@useauthio/react] AuthioProvider projectId is missing \u2014 Lobby cannot resolve your project. Set projectId="proj_\u2026" on <AuthioProvider>.'
|
|
539
583
|
);
|
|
540
584
|
}
|
|
541
|
-
const
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
},
|
|
552
|
-
[]
|
|
553
|
-
);
|
|
585
|
+
const url = await mintLobbySignInUrl({
|
|
586
|
+
apiUrl: p.apiUrl,
|
|
587
|
+
projectId: p.projectId,
|
|
588
|
+
hostedUiUrl: p.signInUrl ?? DEFAULT_SIGN_IN_URL,
|
|
589
|
+
redirectUri: opts.returnTo ?? window.location.href,
|
|
590
|
+
fetchImpl: p.fetchImpl
|
|
591
|
+
});
|
|
592
|
+
window.location.assign(url);
|
|
593
|
+
})();
|
|
594
|
+
}, []);
|
|
554
595
|
const signOut = react.useCallback(async () => {
|
|
555
596
|
const p = propsRef.current;
|
|
556
597
|
const token = storageRef.current.get();
|
|
@@ -623,11 +664,16 @@ function AuthioProvider(props) {
|
|
|
623
664
|
},
|
|
624
665
|
[]
|
|
625
666
|
);
|
|
667
|
+
const resolvedSignInUrl = signInUrl ?? DEFAULT_SIGN_IN_URL;
|
|
626
668
|
const value = react.useMemo(
|
|
627
669
|
() => ({
|
|
628
670
|
user,
|
|
629
671
|
status,
|
|
630
672
|
accessToken,
|
|
673
|
+
apiUrl,
|
|
674
|
+
projectId,
|
|
675
|
+
signInUrl: resolvedSignInUrl,
|
|
676
|
+
fetchImpl,
|
|
631
677
|
getAccessToken,
|
|
632
678
|
signIn,
|
|
633
679
|
signOut,
|
|
@@ -638,6 +684,10 @@ function AuthioProvider(props) {
|
|
|
638
684
|
user,
|
|
639
685
|
status,
|
|
640
686
|
accessToken,
|
|
687
|
+
apiUrl,
|
|
688
|
+
projectId,
|
|
689
|
+
resolvedSignInUrl,
|
|
690
|
+
fetchImpl,
|
|
641
691
|
getAccessToken,
|
|
642
692
|
signIn,
|
|
643
693
|
signOut,
|
|
@@ -831,6 +881,364 @@ function bufferToBase64Url(buf) {
|
|
|
831
881
|
}
|
|
832
882
|
return btoa(bin).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
833
883
|
}
|
|
884
|
+
function signInOrigin(signInUrl) {
|
|
885
|
+
return signInUrl.replace(/\/$/, "");
|
|
886
|
+
}
|
|
887
|
+
function canEnrollPasskeyEmbedded(signInUrl) {
|
|
888
|
+
if (!isBrowser()) return false;
|
|
889
|
+
return window.location.origin === signInOrigin(signInUrl);
|
|
890
|
+
}
|
|
891
|
+
function buildEnrollPasskeyUrl(opts) {
|
|
892
|
+
const url = new URL(signInOrigin(opts.signInUrl));
|
|
893
|
+
url.searchParams.set("mode", "add_credential");
|
|
894
|
+
url.searchParams.set("project_id", opts.projectId);
|
|
895
|
+
url.searchParams.set("email", opts.email);
|
|
896
|
+
url.searchParams.set("token", opts.registerToken);
|
|
897
|
+
if (opts.redirectUri) {
|
|
898
|
+
url.searchParams.set("redirect_uri", opts.redirectUri);
|
|
899
|
+
}
|
|
900
|
+
if (opts.next) {
|
|
901
|
+
url.searchParams.set("next", opts.next);
|
|
902
|
+
}
|
|
903
|
+
return url.toString();
|
|
904
|
+
}
|
|
905
|
+
function bearerHeaders(accessToken, origin) {
|
|
906
|
+
const h = {
|
|
907
|
+
Authorization: `Bearer ${accessToken}`
|
|
908
|
+
};
|
|
909
|
+
if (origin) h["X-Authio-Origin"] = origin;
|
|
910
|
+
return h;
|
|
911
|
+
}
|
|
912
|
+
async function mintPasskeyRegisterIntent(opts) {
|
|
913
|
+
const body = await authioFetch({
|
|
914
|
+
apiUrl: opts.apiUrl,
|
|
915
|
+
projectId: opts.projectId,
|
|
916
|
+
path: "/v1/me/passkeys/register-intent",
|
|
917
|
+
method: "POST",
|
|
918
|
+
body: {},
|
|
919
|
+
signal: opts.signal,
|
|
920
|
+
fetchImpl: opts.fetchImpl,
|
|
921
|
+
extraHeaders: bearerHeaders(opts.accessToken)
|
|
922
|
+
});
|
|
923
|
+
return { token: body.token, expiresIn: body.expires_in };
|
|
924
|
+
}
|
|
925
|
+
async function enrollPasskey(opts) {
|
|
926
|
+
if (!isBrowser()) {
|
|
927
|
+
throw new node.AuthioError({
|
|
928
|
+
code: "not_in_browser",
|
|
929
|
+
message: "enrollPasskey can only be invoked in a browser environment.",
|
|
930
|
+
status: 0
|
|
931
|
+
});
|
|
932
|
+
}
|
|
933
|
+
const intent = await mintPasskeyRegisterIntent(opts);
|
|
934
|
+
const redirectUri = opts.returnUrl ?? (typeof window !== "undefined" ? window.location.href : "");
|
|
935
|
+
const target = buildEnrollPasskeyUrl({
|
|
936
|
+
signInUrl: opts.signInUrl,
|
|
937
|
+
projectId: opts.projectId,
|
|
938
|
+
email: opts.email,
|
|
939
|
+
registerToken: intent.token,
|
|
940
|
+
redirectUri,
|
|
941
|
+
next: opts.next
|
|
942
|
+
});
|
|
943
|
+
window.location.assign(target);
|
|
944
|
+
}
|
|
945
|
+
async function addPasskey(opts) {
|
|
946
|
+
if (!isBrowser()) {
|
|
947
|
+
throw new node.AuthioError({
|
|
948
|
+
code: "not_in_browser",
|
|
949
|
+
message: "addPasskey can only be invoked in a browser environment.",
|
|
950
|
+
status: 0
|
|
951
|
+
});
|
|
952
|
+
}
|
|
953
|
+
const origin = opts.origin ?? window.location.origin;
|
|
954
|
+
const intent = await mintPasskeyRegisterIntent(opts);
|
|
955
|
+
const options = await authioFetch({
|
|
956
|
+
apiUrl: opts.apiUrl,
|
|
957
|
+
projectId: opts.projectId,
|
|
958
|
+
path: "/v1/auth/passkey/register/options",
|
|
959
|
+
method: "POST",
|
|
960
|
+
body: { email: opts.email },
|
|
961
|
+
signal: opts.signal,
|
|
962
|
+
fetchImpl: opts.fetchImpl,
|
|
963
|
+
extraHeaders: bearerHeaders(intent.token, origin)
|
|
964
|
+
});
|
|
965
|
+
let attestation;
|
|
966
|
+
try {
|
|
967
|
+
attestation = await browser.startRegistration({ optionsJSON: options });
|
|
968
|
+
} catch (err) {
|
|
969
|
+
throw new node.AuthioError({
|
|
970
|
+
code: "webauthn_cancelled",
|
|
971
|
+
message: err instanceof Error ? err.message : "Passkey registration cancelled by user.",
|
|
972
|
+
status: 0
|
|
973
|
+
});
|
|
974
|
+
}
|
|
975
|
+
await authioFetch({
|
|
976
|
+
apiUrl: opts.apiUrl,
|
|
977
|
+
projectId: opts.projectId,
|
|
978
|
+
path: "/v1/auth/passkey/register/verify",
|
|
979
|
+
method: "POST",
|
|
980
|
+
body: { email: opts.email, credential: attestation },
|
|
981
|
+
signal: opts.signal,
|
|
982
|
+
fetchImpl: opts.fetchImpl,
|
|
983
|
+
extraHeaders: bearerHeaders(intent.token, origin)
|
|
984
|
+
});
|
|
985
|
+
}
|
|
986
|
+
async function listPasskeys(opts) {
|
|
987
|
+
const res = await authioFetch({
|
|
988
|
+
apiUrl: opts.apiUrl,
|
|
989
|
+
projectId: opts.projectId,
|
|
990
|
+
path: "/v1/me/passkeys",
|
|
991
|
+
signal: opts.signal,
|
|
992
|
+
fetchImpl: opts.fetchImpl,
|
|
993
|
+
extraHeaders: bearerHeaders(opts.accessToken)
|
|
994
|
+
});
|
|
995
|
+
return res.data ?? [];
|
|
996
|
+
}
|
|
997
|
+
async function renamePasskey(opts, credentialId, name) {
|
|
998
|
+
await authioFetch({
|
|
999
|
+
apiUrl: opts.apiUrl,
|
|
1000
|
+
projectId: opts.projectId,
|
|
1001
|
+
path: `/v1/me/passkeys/${encodeURIComponent(credentialId)}`,
|
|
1002
|
+
method: "PATCH",
|
|
1003
|
+
body: { nickname: name },
|
|
1004
|
+
signal: opts.signal,
|
|
1005
|
+
fetchImpl: opts.fetchImpl,
|
|
1006
|
+
extraHeaders: bearerHeaders(opts.accessToken)
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
1009
|
+
async function revokePasskey(opts, credentialId) {
|
|
1010
|
+
await authioFetch({
|
|
1011
|
+
apiUrl: opts.apiUrl,
|
|
1012
|
+
projectId: opts.projectId,
|
|
1013
|
+
path: `/v1/me/passkeys/${encodeURIComponent(credentialId)}`,
|
|
1014
|
+
method: "DELETE",
|
|
1015
|
+
signal: opts.signal,
|
|
1016
|
+
fetchImpl: opts.fetchImpl,
|
|
1017
|
+
extraHeaders: bearerHeaders(opts.accessToken)
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1020
|
+
function usePasskeys() {
|
|
1021
|
+
const ctx = useAuthio();
|
|
1022
|
+
const [passkeys, setPasskeys] = react.useState([]);
|
|
1023
|
+
const [loading, setLoading] = react.useState(true);
|
|
1024
|
+
const [error, setError] = react.useState(null);
|
|
1025
|
+
const refresh = react.useCallback(async () => {
|
|
1026
|
+
if (ctx.status !== "authenticated") {
|
|
1027
|
+
setPasskeys([]);
|
|
1028
|
+
setLoading(false);
|
|
1029
|
+
return;
|
|
1030
|
+
}
|
|
1031
|
+
setLoading(true);
|
|
1032
|
+
setError(null);
|
|
1033
|
+
try {
|
|
1034
|
+
const token = await ctx.getAccessToken();
|
|
1035
|
+
if (!token) {
|
|
1036
|
+
setPasskeys([]);
|
|
1037
|
+
return;
|
|
1038
|
+
}
|
|
1039
|
+
const rows = await listPasskeys({
|
|
1040
|
+
apiUrl: ctx.apiUrl,
|
|
1041
|
+
projectId: ctx.projectId,
|
|
1042
|
+
accessToken: token,
|
|
1043
|
+
fetchImpl: ctx.fetchImpl
|
|
1044
|
+
});
|
|
1045
|
+
setPasskeys(rows);
|
|
1046
|
+
} catch (err) {
|
|
1047
|
+
setError(err instanceof Error ? err.message : "Failed to load passkeys");
|
|
1048
|
+
setPasskeys([]);
|
|
1049
|
+
} finally {
|
|
1050
|
+
setLoading(false);
|
|
1051
|
+
}
|
|
1052
|
+
}, [
|
|
1053
|
+
ctx.status,
|
|
1054
|
+
ctx.getAccessToken,
|
|
1055
|
+
ctx.apiUrl,
|
|
1056
|
+
ctx.projectId,
|
|
1057
|
+
ctx.fetchImpl
|
|
1058
|
+
]);
|
|
1059
|
+
react.useEffect(() => {
|
|
1060
|
+
void refresh();
|
|
1061
|
+
}, [refresh, ctx.status]);
|
|
1062
|
+
const rename = react.useCallback(
|
|
1063
|
+
async (credentialId, nickname) => {
|
|
1064
|
+
const token = await ctx.getAccessToken();
|
|
1065
|
+
if (!token) throw new Error("Not signed in");
|
|
1066
|
+
await renamePasskey(
|
|
1067
|
+
{
|
|
1068
|
+
apiUrl: ctx.apiUrl,
|
|
1069
|
+
projectId: ctx.projectId,
|
|
1070
|
+
accessToken: token,
|
|
1071
|
+
fetchImpl: ctx.fetchImpl
|
|
1072
|
+
},
|
|
1073
|
+
credentialId,
|
|
1074
|
+
nickname
|
|
1075
|
+
);
|
|
1076
|
+
await refresh();
|
|
1077
|
+
},
|
|
1078
|
+
[ctx.getAccessToken, ctx.apiUrl, ctx.projectId, ctx.fetchImpl, refresh]
|
|
1079
|
+
);
|
|
1080
|
+
const revoke = react.useCallback(
|
|
1081
|
+
async (credentialId) => {
|
|
1082
|
+
const token = await ctx.getAccessToken();
|
|
1083
|
+
if (!token) throw new Error("Not signed in");
|
|
1084
|
+
await revokePasskey(
|
|
1085
|
+
{
|
|
1086
|
+
apiUrl: ctx.apiUrl,
|
|
1087
|
+
projectId: ctx.projectId,
|
|
1088
|
+
accessToken: token,
|
|
1089
|
+
fetchImpl: ctx.fetchImpl
|
|
1090
|
+
},
|
|
1091
|
+
credentialId
|
|
1092
|
+
);
|
|
1093
|
+
await refresh();
|
|
1094
|
+
},
|
|
1095
|
+
[ctx.getAccessToken, ctx.apiUrl, ctx.projectId, ctx.fetchImpl, refresh]
|
|
1096
|
+
);
|
|
1097
|
+
const enroll = react.useCallback(
|
|
1098
|
+
async (opts) => {
|
|
1099
|
+
const token = await ctx.getAccessToken();
|
|
1100
|
+
const email = ctx.user?.email;
|
|
1101
|
+
if (!token || !email) throw new Error("Not signed in");
|
|
1102
|
+
await enrollPasskey({
|
|
1103
|
+
apiUrl: ctx.apiUrl,
|
|
1104
|
+
projectId: ctx.projectId,
|
|
1105
|
+
accessToken: token,
|
|
1106
|
+
fetchImpl: ctx.fetchImpl,
|
|
1107
|
+
email,
|
|
1108
|
+
signInUrl: ctx.signInUrl,
|
|
1109
|
+
returnUrl: opts?.returnUrl,
|
|
1110
|
+
next: opts?.next
|
|
1111
|
+
});
|
|
1112
|
+
},
|
|
1113
|
+
[
|
|
1114
|
+
ctx.getAccessToken,
|
|
1115
|
+
ctx.user?.email,
|
|
1116
|
+
ctx.apiUrl,
|
|
1117
|
+
ctx.projectId,
|
|
1118
|
+
ctx.fetchImpl,
|
|
1119
|
+
ctx.signInUrl
|
|
1120
|
+
]
|
|
1121
|
+
);
|
|
1122
|
+
return { passkeys, loading, error, refresh, rename, revoke, enroll };
|
|
1123
|
+
}
|
|
1124
|
+
function PasskeyManager({
|
|
1125
|
+
className,
|
|
1126
|
+
enrollReturnUrl,
|
|
1127
|
+
enrollNext
|
|
1128
|
+
}) {
|
|
1129
|
+
const { passkeys, loading, error, rename, revoke, enroll } = usePasskeys();
|
|
1130
|
+
const [busyId, setBusyId] = react.useState(null);
|
|
1131
|
+
const [actionError, setActionError] = react.useState(null);
|
|
1132
|
+
const [enrolling, setEnrolling] = react.useState(false);
|
|
1133
|
+
async function onRename(id, nickname) {
|
|
1134
|
+
setBusyId(id);
|
|
1135
|
+
setActionError(null);
|
|
1136
|
+
try {
|
|
1137
|
+
await rename(id, nickname);
|
|
1138
|
+
} catch (err) {
|
|
1139
|
+
setActionError(err instanceof Error ? err.message : "Rename failed");
|
|
1140
|
+
} finally {
|
|
1141
|
+
setBusyId(null);
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
async function onRevoke(id) {
|
|
1145
|
+
setBusyId(id);
|
|
1146
|
+
setActionError(null);
|
|
1147
|
+
try {
|
|
1148
|
+
await revoke(id);
|
|
1149
|
+
} catch (err) {
|
|
1150
|
+
setActionError(err instanceof Error ? err.message : "Revoke failed");
|
|
1151
|
+
} finally {
|
|
1152
|
+
setBusyId(null);
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
async function onEnroll() {
|
|
1156
|
+
setEnrolling(true);
|
|
1157
|
+
setActionError(null);
|
|
1158
|
+
try {
|
|
1159
|
+
await enroll({ returnUrl: enrollReturnUrl, next: enrollNext });
|
|
1160
|
+
} catch (err) {
|
|
1161
|
+
setEnrolling(false);
|
|
1162
|
+
setActionError(err instanceof Error ? err.message : "Could not start enrollment");
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("section", { className, "aria-labelledby": "authio-passkey-manager-title", children: [
|
|
1166
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "authio-passkey-manager__header", children: [
|
|
1167
|
+
/* @__PURE__ */ jsxRuntime.jsx("h2", { id: "authio-passkey-manager-title", children: "Passkeys" }),
|
|
1168
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1169
|
+
"button",
|
|
1170
|
+
{
|
|
1171
|
+
type: "button",
|
|
1172
|
+
onClick: () => void onEnroll(),
|
|
1173
|
+
disabled: enrolling || loading,
|
|
1174
|
+
children: enrolling ? "Redirecting\u2026" : "Add passkey"
|
|
1175
|
+
}
|
|
1176
|
+
)
|
|
1177
|
+
] }),
|
|
1178
|
+
(error || actionError) && /* @__PURE__ */ jsxRuntime.jsx("p", { role: "alert", className: "authio-passkey-manager__error", children: error ?? actionError }),
|
|
1179
|
+
loading ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "authio-passkey-manager__loading", children: "Loading passkeys\u2026" }) : passkeys.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "authio-passkey-manager__empty", children: "No passkeys yet. Add one to sign in faster on this account." }) : /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "authio-passkey-manager__list", children: passkeys.map((p) => /* @__PURE__ */ jsxRuntime.jsx("li", { className: "authio-passkey-manager__item", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1180
|
+
PasskeyRow,
|
|
1181
|
+
{
|
|
1182
|
+
passkey: p,
|
|
1183
|
+
busy: busyId === p.id,
|
|
1184
|
+
onRename,
|
|
1185
|
+
onRevoke
|
|
1186
|
+
}
|
|
1187
|
+
) }, p.id)) })
|
|
1188
|
+
] });
|
|
1189
|
+
}
|
|
1190
|
+
function PasskeyRow({
|
|
1191
|
+
passkey,
|
|
1192
|
+
busy,
|
|
1193
|
+
onRename,
|
|
1194
|
+
onRevoke
|
|
1195
|
+
}) {
|
|
1196
|
+
const [nickname, setNickname] = react.useState(passkey.nickname ?? "");
|
|
1197
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "authio-passkey-manager__row", children: [
|
|
1198
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
1199
|
+
/* @__PURE__ */ jsxRuntime.jsx("strong", { children: passkey.authenticator_name }),
|
|
1200
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "authio-passkey-manager__meta", children: [
|
|
1201
|
+
"Added ",
|
|
1202
|
+
new Date(passkey.created_at).toLocaleDateString(),
|
|
1203
|
+
passkey.last_used_at ? ` \xB7 Last used ${new Date(passkey.last_used_at).toLocaleDateString()}` : ""
|
|
1204
|
+
] })
|
|
1205
|
+
] }),
|
|
1206
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1207
|
+
"form",
|
|
1208
|
+
{
|
|
1209
|
+
className: "authio-passkey-manager__rename",
|
|
1210
|
+
onSubmit: (e) => {
|
|
1211
|
+
e.preventDefault();
|
|
1212
|
+
void onRename(passkey.id, nickname.trim());
|
|
1213
|
+
},
|
|
1214
|
+
children: [
|
|
1215
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1216
|
+
"input",
|
|
1217
|
+
{
|
|
1218
|
+
type: "text",
|
|
1219
|
+
value: nickname,
|
|
1220
|
+
onChange: (e) => setNickname(e.target.value),
|
|
1221
|
+
placeholder: "Nickname",
|
|
1222
|
+
maxLength: 64,
|
|
1223
|
+
disabled: busy
|
|
1224
|
+
}
|
|
1225
|
+
),
|
|
1226
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "submit", disabled: busy, children: "Save" })
|
|
1227
|
+
]
|
|
1228
|
+
}
|
|
1229
|
+
),
|
|
1230
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1231
|
+
"button",
|
|
1232
|
+
{
|
|
1233
|
+
type: "button",
|
|
1234
|
+
disabled: busy,
|
|
1235
|
+
onClick: () => void onRevoke(passkey.id),
|
|
1236
|
+
className: "authio-passkey-manager__revoke",
|
|
1237
|
+
children: "Revoke"
|
|
1238
|
+
}
|
|
1239
|
+
)
|
|
1240
|
+
] });
|
|
1241
|
+
}
|
|
834
1242
|
|
|
835
1243
|
// src/locate.ts
|
|
836
1244
|
function captureClientLocation(opts = {}) {
|
|
@@ -870,14 +1278,25 @@ Object.defineProperty(exports, "AuthioError", {
|
|
|
870
1278
|
});
|
|
871
1279
|
exports.AuthioContext = AuthioContext;
|
|
872
1280
|
exports.AuthioProvider = AuthioProvider;
|
|
1281
|
+
exports.PasskeyManager = PasskeyManager;
|
|
873
1282
|
exports.RedirectToSignIn = RedirectToSignIn;
|
|
874
1283
|
exports.SignedIn = SignedIn;
|
|
875
1284
|
exports.SignedOut = SignedOut;
|
|
1285
|
+
exports.addPasskey = addPasskey;
|
|
1286
|
+
exports.buildEnrollPasskeyUrl = buildEnrollPasskeyUrl;
|
|
1287
|
+
exports.canEnrollPasskeyEmbedded = canEnrollPasskeyEmbedded;
|
|
876
1288
|
exports.captureClientLocation = captureClientLocation;
|
|
1289
|
+
exports.enrollPasskey = enrollPasskey;
|
|
1290
|
+
exports.listPasskeys = listPasskeys;
|
|
1291
|
+
exports.mintPasskeyRegisterIntent = mintPasskeyRegisterIntent;
|
|
1292
|
+
exports.renamePasskey = renamePasskey;
|
|
1293
|
+
exports.revokePasskey = revokePasskey;
|
|
1294
|
+
exports.signInOrigin = signInOrigin;
|
|
877
1295
|
exports.signInWithMagicLink = signInWithMagicLink;
|
|
878
1296
|
exports.signInWithPasskey = signInWithPasskey;
|
|
879
1297
|
exports.useAuthio = useAuthio;
|
|
880
1298
|
exports.useAuthioRequired = useAuthioRequired;
|
|
1299
|
+
exports.usePasskeys = usePasskeys;
|
|
881
1300
|
exports.wrapFetchError = wrapFetchError;
|
|
882
1301
|
//# sourceMappingURL=index.cjs.map
|
|
883
1302
|
//# sourceMappingURL=index.cjs.map
|