@useauthio/react 0.3.0 → 0.3.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/CHANGELOG.md CHANGED
@@ -4,6 +4,41 @@ 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.3.1] — 2026-11-21
8
+
9
+ ### Fixed
10
+ - **`signInWithPasskey` no longer crashes on a risk step-up.** When
11
+ auth-core's risk engine answered `decision: "step_up"` (HTTP 200, no
12
+ `user`), the helper read `verifyRes.user.id` and threw
13
+ `Cannot read properties of undefined (reading 'id')`. Sign-in helpers
14
+ now never assume `user` or tokens are present.
15
+
16
+ ### Added
17
+ - `AuthioStepUpRequiredError` (code `step_up_required`, thrown by
18
+ `signInWithPasskey` and `verifyEmailOtp`) with `stepUpUrl`,
19
+ `challengeId`, `requiredMethod`, `reasons` and `enrollmentRequired`.
20
+ `stepUpUrl` is the hosted step-up page from auth-core's new
21
+ `step_up_url` field. `isStepUpRequired(err)` type guard.
22
+ - `AuthioSignInDeniedError` (code `sign_in_denied`) for risk or policy
23
+ denies (403 `decision: "block"`), carrying the server's message plus
24
+ `denyCode` and `reasons`.
25
+ - `invalid_response` when a sign-in call returns 200 without a session.
26
+ - `AUTHIO_MESSAGES`, the SDK's user-facing copy.
27
+
28
+ ### Changed
29
+ - Every error message the SDK writes itself is now plain English and
30
+ actionable. Raw browser or network text ("Failed to fetch",
31
+ WebAuthn's "The operation either timed out or was not allowed…") moves
32
+ to `err.cause`. Server-sent messages are passed through unchanged.
33
+ - The SDK's own request timeout now reports code `timeout` (it used to
34
+ report `aborted`).
35
+ - Risk denies used to surface auth-core's code (for example
36
+ `blocked_by_risk_policy`). They now use `sign_in_denied`, and the
37
+ original code is on `err.denyCode`.
38
+ - `usePasskeys` actions throw `AuthioError` `not_signed_in`, not a bare
39
+ `Error`. Adding a passkey that already exists reports
40
+ `webauthn_already_registered`.
41
+
7
42
  ## [0.3.0] — 2026-09-03
8
43
 
9
44
  ### Added
package/README.md CHANGED
@@ -246,7 +246,10 @@ Runs the full WebAuthn assertion ceremony against
246
246
  `/v1/auth/passkey/login/options` + `/v1/auth/passkey/login/verify`.
247
247
  Returns `{ accessToken, refreshToken?, user }`. Throws `AuthioError`
248
248
  with codes `not_in_browser`, `webauthn_unsupported`,
249
- `webauthn_cancelled`, or any identity API error code on a step failure.
249
+ `webauthn_cancelled`, `step_up_required`, `sign_in_denied`,
250
+ `invalid_response`, or any identity API error code on a step failure.
251
+ `verifyEmailOtp` throws the same risk-engine codes. See
252
+ [Handling risk checks](#handling-risk-checks-step-up-and-deny).
250
253
 
251
254
  The returned `refreshToken` is included for completeness but the SDK
252
255
  itself never persists it — identity API also sets the refresh cookie via
@@ -291,6 +294,39 @@ await addPasskey({
291
294
  Re-exported from `@useauthio/node`. Thrown by every helper and the
292
295
  provider on failure. Shape: `{ code, message, status, requestId? }`.
293
296
 
297
+ `message` is always plain English and safe to show to users. Raw
298
+ browser or network errors are kept on `err.cause` for debugging.
299
+
300
+ ### Handling risk checks (step-up and deny)
301
+
302
+ Authio's risk engine can ask for one more check (for example, a sign-in
303
+ from a new country) or refuse a sign-in. Sign-in helpers never return a
304
+ half-finished session; they throw:
305
+
306
+ | `err.code` | Class | What to do |
307
+ |------------|-------|------------|
308
+ | `step_up_required` | `AuthioStepUpRequiredError` | Send the user to `err.stepUpUrl` (the hosted step-up page). Also has `challengeId`, `requiredMethod`, `reasons`. |
309
+ | `sign_in_denied` | `AuthioSignInDeniedError` | Show `err.message` (the server's reason). `err.denyCode` is the machine code, for example `blocked_by_geo_policy`. |
310
+ | `invalid_response` | `AuthioError` | The server answered without a session. Ask the user to try again. |
311
+
312
+ ```ts
313
+ import { signInWithPasskey, isStepUpRequired, AuthioError } from "@useauthio/react";
314
+
315
+ try {
316
+ const result = await signInWithPasskey({ apiUrl, projectId });
317
+ await handleSignInResult(result);
318
+ } catch (err) {
319
+ if (isStepUpRequired(err) && err.stepUpUrl) {
320
+ window.location.assign(err.stepUpUrl);
321
+ return;
322
+ }
323
+ setError(err instanceof AuthioError ? err.message : "Something went wrong. Please try again.");
324
+ }
325
+ ```
326
+
327
+ `stepUpUrl` is `undefined` when auth-core predates the field or the
328
+ project has no hosted UI configured.
329
+
294
330
  ---
295
331
 
296
332
  ## When to use this vs. `@useauthio/nextjs`
package/dist/index.cjs CHANGED
@@ -6,32 +6,146 @@ var jsxRuntime = require('react/jsx-runtime');
6
6
  var browser = require('@simplewebauthn/browser');
7
7
 
8
8
  // src/provider.tsx
9
+ var AUTHIO_MESSAGES = {
10
+ network_error: "We couldn't reach the sign-in service. Check your internet connection and try again.",
11
+ timeout: "The sign-in service took too long to respond. Please try again.",
12
+ aborted: "The request was cancelled before it finished. Please try again.",
13
+ invalid_response: "We couldn't finish signing you in because the sign-in service sent an unexpected response. Please try again.",
14
+ step_up_required: "For your security, we need one more check before signing you in.",
15
+ sign_in_denied: "We couldn't sign you in. If you think this is a mistake, contact support or your administrator.",
16
+ rate_limited: "Too many attempts. Please wait a moment and try again.",
17
+ server_error: "Something went wrong on our side. Please try again in a moment.",
18
+ request_failed: "We couldn't complete that request. Please try again.",
19
+ webauthn_cancelled: "Passkey sign-in was cancelled or timed out. Please try again.",
20
+ webauthn_registration_cancelled: "Passkey setup was cancelled or timed out. Please try again.",
21
+ webauthn_already_registered: "This device already has a passkey for your account.",
22
+ webauthn_unsupported: "This browser doesn't support passkeys. Try a different browser, or sign in another way.",
23
+ not_signed_in: "You need to be signed in to do that. Please sign in and try again.",
24
+ token_rejected: "We couldn't verify your sign-in. Please sign in again."
25
+ };
26
+ function withCause(err, cause) {
27
+ if (cause !== void 0) {
28
+ Object.defineProperty(err, "cause", {
29
+ value: cause,
30
+ enumerable: false,
31
+ configurable: true,
32
+ writable: true
33
+ });
34
+ }
35
+ return err;
36
+ }
9
37
  function wrapFetchError(err, fallbackCode = "network_error") {
10
38
  if (err instanceof node.AuthioError) return err;
11
- if (err instanceof Error && err.name === "AbortError") {
12
- return new node.AuthioError({
13
- code: "aborted",
14
- message: err.message || "Request aborted",
15
- status: 0
39
+ const e = err && typeof err === "object" ? err : {};
40
+ const name = typeof e.name === "string" ? e.name : "";
41
+ const rawMessage = typeof e.message === "string" ? e.message : "";
42
+ const isTimeout = name === "TimeoutError" || /timed? ?out/i.test(rawMessage);
43
+ if (isTimeout) {
44
+ return withCause(
45
+ new node.AuthioError({
46
+ code: "timeout",
47
+ message: AUTHIO_MESSAGES.timeout,
48
+ status: 0
49
+ }),
50
+ err
51
+ );
52
+ }
53
+ if (name === "AbortError") {
54
+ return withCause(
55
+ new node.AuthioError({
56
+ code: "aborted",
57
+ message: AUTHIO_MESSAGES.aborted,
58
+ status: 0
59
+ }),
60
+ err
61
+ );
62
+ }
63
+ const message = fallbackCode === "network_error" ? AUTHIO_MESSAGES.network_error : AUTHIO_MESSAGES.request_failed;
64
+ return withCause(
65
+ new node.AuthioError({ code: fallbackCode, message, status: 0 }),
66
+ err
67
+ );
68
+ }
69
+ function messageForStatus(status) {
70
+ if (status === 429) return AUTHIO_MESSAGES.rate_limited;
71
+ if (status >= 500) return AUTHIO_MESSAGES.server_error;
72
+ return AUTHIO_MESSAGES.request_failed;
73
+ }
74
+ var AuthioStepUpRequiredError = class extends node.AuthioError {
75
+ stepUpUrl;
76
+ challengeId;
77
+ requiredMethod;
78
+ reasons;
79
+ enrollmentRequired;
80
+ /** auth-core's own explanation of the step, when it sent one. */
81
+ serverMessage;
82
+ constructor(opts) {
83
+ super({
84
+ code: "step_up_required",
85
+ message: AUTHIO_MESSAGES.step_up_required,
86
+ status: opts.status,
87
+ requestId: opts.requestId
16
88
  });
89
+ this.name = "AuthioStepUpRequiredError";
90
+ this.stepUpUrl = opts.stepUpUrl;
91
+ this.challengeId = opts.challengeId;
92
+ this.requiredMethod = opts.requiredMethod;
93
+ this.reasons = opts.reasons ?? [];
94
+ this.enrollmentRequired = Boolean(opts.enrollmentRequired);
95
+ this.serverMessage = opts.serverMessage;
17
96
  }
18
- if (err instanceof Error && /timeout/i.test(err.message)) {
19
- return new node.AuthioError({
20
- code: "timeout",
21
- message: err.message,
22
- status: 0
97
+ };
98
+ var AuthioSignInDeniedError = class extends node.AuthioError {
99
+ denyCode;
100
+ reasons;
101
+ constructor(opts) {
102
+ super({
103
+ code: "sign_in_denied",
104
+ message: nonEmpty(opts.message) ?? AUTHIO_MESSAGES.sign_in_denied,
105
+ status: opts.status,
106
+ requestId: opts.requestId
23
107
  });
108
+ this.name = "AuthioSignInDeniedError";
109
+ this.denyCode = opts.denyCode;
110
+ this.reasons = opts.reasons ?? [];
24
111
  }
25
- const message = err instanceof Error ? err.message : "Unknown network error";
26
- return new node.AuthioError({
27
- code: fallbackCode,
28
- message,
29
- status: 0
30
- });
112
+ };
113
+ function isStepUpRequired(err) {
114
+ return err instanceof AuthioStepUpRequiredError;
115
+ }
116
+ function riskDecisionError(body, status) {
117
+ if (!body || typeof body !== "object") return null;
118
+ const decision = typeof body.decision === "string" ? body.decision : "";
119
+ const reasons = Array.isArray(body.reasons) ? body.reasons.filter((r) => typeof r === "string") : [];
120
+ if (decision === "step_up" || body.code === "step_up_required") {
121
+ return new AuthioStepUpRequiredError({
122
+ status,
123
+ stepUpUrl: nonEmpty(body.step_up_url),
124
+ challengeId: nonEmpty(body.challenge_id),
125
+ requiredMethod: nonEmpty(body.required_method),
126
+ reasons,
127
+ enrollmentRequired: body.enrollment_required === true,
128
+ serverMessage: nonEmpty(body.message),
129
+ requestId: body.request_id
130
+ });
131
+ }
132
+ if (decision === "block" || decision === "deny") {
133
+ return new AuthioSignInDeniedError({
134
+ status,
135
+ message: body.message,
136
+ denyCode: nonEmpty(body.code) ?? nonEmpty(body.error),
137
+ reasons,
138
+ requestId: body.request_id
139
+ });
140
+ }
141
+ return null;
142
+ }
143
+ function nonEmpty(v) {
144
+ return typeof v === "string" && v.trim() !== "" ? v : void 0;
31
145
  }
32
146
 
33
147
  // src/version.ts
34
- var SDK_VERSION = "0.3.0";
148
+ var SDK_VERSION = "0.3.1";
35
149
  var SDK_USER_AGENT = `react/${SDK_VERSION}`;
36
150
 
37
151
  // src/fetch.ts
@@ -76,10 +190,14 @@ async function authioFetch(opts) {
76
190
  if (opts.signal) opts.signal.removeEventListener("abort", onCallerAbort);
77
191
  }
78
192
  if (!res.ok) {
79
- const body = await res.json().catch(() => ({}));
193
+ const raw = await res.json().catch(() => ({}));
194
+ const body = raw && typeof raw === "object" ? raw : {};
195
+ const risk = riskDecisionError(body, res.status);
196
+ if (risk) throw risk;
197
+ const message = typeof body.message === "string" && body.message.trim() !== "" ? body.message : messageForStatus(res.status);
80
198
  throw new node.AuthioError({
81
199
  code: body.code ?? body.error ?? "request_failed",
82
- message: body.message ?? `Request to ${opts.path} failed with status ${res.status}`,
200
+ message,
83
201
  status: res.status,
84
202
  requestId: body.request_id
85
203
  });
@@ -92,7 +210,7 @@ async function authioFetch(opts) {
92
210
  } catch {
93
211
  throw new node.AuthioError({
94
212
  code: "invalid_response",
95
- message: `Response from ${opts.path} was not valid JSON`,
213
+ message: AUTHIO_MESSAGES.invalid_response,
96
214
  status: res.status
97
215
  });
98
216
  }
@@ -399,7 +517,8 @@ async function mintLobbySignInUrl(opts) {
399
517
  project_id: opts.projectId,
400
518
  redirect_uri: opts.redirectUri,
401
519
  ...opts.next ? { next: opts.next } : {},
402
- ...opts.organizationId ? { organization_id: opts.organizationId } : {}
520
+ ...opts.organizationId ? { organization_id: opts.organizationId } : {},
521
+ ...opts.xrayVisitorProof ? { xray_visitor_proof: opts.xrayVisitorProof } : {}
403
522
  })
404
523
  }
405
524
  );
@@ -423,6 +542,9 @@ async function mintLobbySignInUrl(opts) {
423
542
  if (opts.organizationId) {
424
543
  target.searchParams.set("organization_id", opts.organizationId);
425
544
  }
545
+ if (opts.xrayVisitorProof) {
546
+ target.searchParams.set("xray_visitor_proof", opts.xrayVisitorProof);
547
+ }
426
548
  return target.toString();
427
549
  }
428
550
 
@@ -803,7 +925,7 @@ function AuthioProvider(props) {
803
925
  setStatus("unauthenticated");
804
926
  throw new node.AuthioError({
805
927
  code: "token_rejected",
806
- message: "Authio rejected the handed-off access token signature.",
928
+ message: "We couldn't verify your sign-in. Please sign in again.",
807
929
  status: 0
808
930
  });
809
931
  }
@@ -982,24 +1104,51 @@ async function signInWithMagicLink(opts) {
982
1104
  // auth-core's magic-link send reads the recipient as `destination`
983
1105
  // (email or E.164), NOT `email`. See magiclink.go magicLinkSendReq.
984
1106
  destination: opts.email,
985
- redirect_uri: opts.redirectUri
1107
+ redirect_uri: opts.redirectUri,
1108
+ ...opts.xrayVisitorProof ? { xray_visitor_proof: opts.xrayVisitorProof } : {}
986
1109
  },
987
1110
  signal: opts.signal,
988
1111
  fetchImpl: opts.fetch
989
1112
  });
990
1113
  }
1114
+ function sessionFromResponse(res, status = 200) {
1115
+ const risk = riskDecisionError(res, status);
1116
+ if (risk) throw risk;
1117
+ const accessToken = res && typeof res.access_token === "string" ? res.access_token : "";
1118
+ const user = res && res.user && typeof res.user === "object" ? res.user : null;
1119
+ const userId = user && typeof user.id === "string" ? user.id : "";
1120
+ if (!res || !accessToken || !user || !userId) {
1121
+ throw new node.AuthioError({
1122
+ code: "invalid_response",
1123
+ message: AUTHIO_MESSAGES.invalid_response,
1124
+ status
1125
+ });
1126
+ }
1127
+ return {
1128
+ accessToken,
1129
+ refreshToken: typeof res.refresh_token === "string" ? res.refresh_token : void 0,
1130
+ sessionPolicy: coerceSessionPolicy(res.session_policy),
1131
+ user: {
1132
+ id: userId,
1133
+ email: typeof user.email === "string" ? user.email : "",
1134
+ emailVerified: Boolean(user.emailVerified ?? user.email_verified),
1135
+ name: user.name,
1136
+ avatarUrl: user.avatarUrl ?? user.avatar_url
1137
+ }
1138
+ };
1139
+ }
991
1140
  async function signInWithPasskey(opts) {
992
1141
  if (!isBrowser() || typeof navigator === "undefined") {
993
1142
  throw new node.AuthioError({
994
1143
  code: "not_in_browser",
995
- message: "signInWithPasskey can only be invoked in a browser environment.",
1144
+ message: "Passkey sign-in only works in a web browser. Call signInWithPasskey from client-side code.",
996
1145
  status: 0
997
1146
  });
998
1147
  }
999
1148
  if (!navigator.credentials || !navigator.credentials.get) {
1000
1149
  throw new node.AuthioError({
1001
1150
  code: "webauthn_unsupported",
1002
- message: "This browser does not support WebAuthn (passkeys).",
1151
+ message: AUTHIO_MESSAGES.webauthn_unsupported,
1003
1152
  status: 0
1004
1153
  });
1005
1154
  }
@@ -1012,6 +1161,13 @@ async function signInWithPasskey(opts) {
1012
1161
  signal: opts.signal,
1013
1162
  fetchImpl: opts.fetch
1014
1163
  });
1164
+ if (!options || typeof options.challenge !== "string" || !options.challenge) {
1165
+ throw new node.AuthioError({
1166
+ code: "invalid_response",
1167
+ message: AUTHIO_MESSAGES.invalid_response,
1168
+ status: 200
1169
+ });
1170
+ }
1015
1171
  const publicKey = {
1016
1172
  challenge: base64UrlToBuffer(options.challenge),
1017
1173
  rpId: options.rpId,
@@ -1030,16 +1186,18 @@ async function signInWithPasskey(opts) {
1030
1186
  signal: opts.signal
1031
1187
  });
1032
1188
  } catch (err) {
1033
- throw new node.AuthioError({
1189
+ const e = new node.AuthioError({
1034
1190
  code: "webauthn_cancelled",
1035
- message: err instanceof Error ? err.message : "Passkey ceremony cancelled by user.",
1191
+ message: AUTHIO_MESSAGES.webauthn_cancelled,
1036
1192
  status: 0
1037
1193
  });
1194
+ Object.defineProperty(e, "cause", { value: err, enumerable: false });
1195
+ throw e;
1038
1196
  }
1039
1197
  if (!credential) {
1040
1198
  throw new node.AuthioError({
1041
1199
  code: "webauthn_cancelled",
1042
- message: "Passkey ceremony returned no credential.",
1200
+ message: AUTHIO_MESSAGES.webauthn_cancelled,
1043
1201
  status: 0
1044
1202
  });
1045
1203
  }
@@ -1065,27 +1223,15 @@ async function signInWithPasskey(opts) {
1065
1223
  body: {
1066
1224
  credential: webauthnCredential,
1067
1225
  ...opts.next ? { next: opts.next } : {},
1068
- ...opts.organizationId ? { organization_id: opts.organizationId } : {}
1226
+ ...opts.organizationId ? { organization_id: opts.organizationId } : {},
1227
+ ...opts.xrayVisitorProof ? { xray_visitor_proof: opts.xrayVisitorProof } : {}
1069
1228
  },
1070
1229
  extraHeaders: deviceSignalsExtraHeaders(),
1071
1230
  credentials: "include",
1072
1231
  signal: opts.signal,
1073
1232
  fetchImpl: opts.fetch
1074
1233
  });
1075
- return {
1076
- accessToken: verifyRes.access_token,
1077
- refreshToken: verifyRes.refresh_token,
1078
- sessionPolicy: coerceSessionPolicy(verifyRes.session_policy),
1079
- user: {
1080
- id: verifyRes.user.id,
1081
- email: verifyRes.user.email,
1082
- emailVerified: Boolean(
1083
- verifyRes.user.emailVerified ?? verifyRes.user.email_verified
1084
- ),
1085
- name: verifyRes.user.name,
1086
- avatarUrl: verifyRes.user.avatarUrl ?? verifyRes.user.avatar_url
1087
- }
1088
- };
1234
+ return sessionFromResponse(verifyRes);
1089
1235
  }
1090
1236
  async function sendEmailOtp(opts) {
1091
1237
  await authioFetch({
@@ -1097,7 +1243,8 @@ async function sendEmailOtp(opts) {
1097
1243
  email: opts.email,
1098
1244
  ...opts.redirectUri ? { redirect_uri: opts.redirectUri } : {},
1099
1245
  ...opts.next ? { next: opts.next } : {},
1100
- ...opts.organizationId ? { organization_id: opts.organizationId } : {}
1246
+ ...opts.organizationId ? { organization_id: opts.organizationId } : {},
1247
+ ...opts.xrayVisitorProof ? { xray_visitor_proof: opts.xrayVisitorProof } : {}
1101
1248
  },
1102
1249
  signal: opts.signal,
1103
1250
  fetchImpl: opts.fetch
@@ -1116,33 +1263,14 @@ async function verifyEmailOtp(opts) {
1116
1263
  ...opts.next ? { next: opts.next } : {},
1117
1264
  ...opts.organizationId ? { organization_id: opts.organizationId } : {},
1118
1265
  ...opts.clientLocation ? { client_location: opts.clientLocation } : {},
1119
- ...opts.deviceSignals ? { device_signals: opts.deviceSignals } : {}
1266
+ ...opts.deviceSignals ? { device_signals: opts.deviceSignals } : {},
1267
+ ...opts.xrayVisitorProof ? { xray_visitor_proof: opts.xrayVisitorProof } : {}
1120
1268
  },
1121
1269
  credentials: "include",
1122
1270
  signal: opts.signal,
1123
1271
  fetchImpl: opts.fetch
1124
1272
  });
1125
- if (verifyRes.decision === "step_up") {
1126
- throw new node.AuthioError({
1127
- code: "step_up_required",
1128
- message: "Additional verification is required. Complete the step-up challenge on the hosted sign-in page.",
1129
- status: 200
1130
- });
1131
- }
1132
- return {
1133
- accessToken: verifyRes.access_token,
1134
- refreshToken: verifyRes.refresh_token,
1135
- sessionPolicy: coerceSessionPolicy(verifyRes.session_policy),
1136
- user: {
1137
- id: verifyRes.user.id,
1138
- email: verifyRes.user.email,
1139
- emailVerified: Boolean(
1140
- verifyRes.user.emailVerified ?? verifyRes.user.email_verified
1141
- ),
1142
- name: verifyRes.user.name,
1143
- avatarUrl: verifyRes.user.avatarUrl ?? verifyRes.user.avatar_url
1144
- }
1145
- };
1273
+ return sessionFromResponse(verifyRes);
1146
1274
  }
1147
1275
  function base64UrlToBuffer(b64u) {
1148
1276
  const padded = b64u.replace(/-/g, "+").replace(/_/g, "/").padEnd(b64u.length + (4 - b64u.length % 4) % 4, "=");
@@ -1204,7 +1332,7 @@ async function enrollPasskey(opts) {
1204
1332
  if (!isBrowser()) {
1205
1333
  throw new node.AuthioError({
1206
1334
  code: "not_in_browser",
1207
- message: "enrollPasskey can only be invoked in a browser environment.",
1335
+ message: "Passkey setup only works in a web browser. Call enrollPasskey from client-side code.",
1208
1336
  status: 0
1209
1337
  });
1210
1338
  }
@@ -1224,7 +1352,7 @@ async function addPasskey(opts) {
1224
1352
  if (!isBrowser()) {
1225
1353
  throw new node.AuthioError({
1226
1354
  code: "not_in_browser",
1227
- message: "addPasskey can only be invoked in a browser environment.",
1355
+ message: "Passkey setup only works in a web browser. Call addPasskey from client-side code.",
1228
1356
  status: 0
1229
1357
  });
1230
1358
  }
@@ -1244,11 +1372,14 @@ async function addPasskey(opts) {
1244
1372
  try {
1245
1373
  attestation = await browser.startRegistration({ optionsJSON: options });
1246
1374
  } catch (err) {
1247
- throw new node.AuthioError({
1248
- code: "webauthn_cancelled",
1249
- message: err instanceof Error ? err.message : "Passkey registration cancelled by user.",
1375
+ const already = err instanceof Error && (err.name === "InvalidStateError" || err.code === "ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED");
1376
+ const e = new node.AuthioError({
1377
+ code: already ? "webauthn_already_registered" : "webauthn_cancelled",
1378
+ message: already ? AUTHIO_MESSAGES.webauthn_already_registered : AUTHIO_MESSAGES.webauthn_registration_cancelled,
1250
1379
  status: 0
1251
1380
  });
1381
+ Object.defineProperty(e, "cause", { value: err, enumerable: false });
1382
+ throw e;
1252
1383
  }
1253
1384
  await authioFetch({
1254
1385
  apiUrl: opts.apiUrl,
@@ -1295,6 +1426,13 @@ async function revokePasskey(opts, credentialId) {
1295
1426
  extraHeaders: bearerHeaders(opts.accessToken)
1296
1427
  });
1297
1428
  }
1429
+ function notSignedIn() {
1430
+ return new node.AuthioError({
1431
+ code: "not_signed_in",
1432
+ message: AUTHIO_MESSAGES.not_signed_in,
1433
+ status: 401
1434
+ });
1435
+ }
1298
1436
  function usePasskeys() {
1299
1437
  const ctx = useAuthio();
1300
1438
  const [passkeys, setPasskeys] = react.useState([]);
@@ -1322,7 +1460,7 @@ function usePasskeys() {
1322
1460
  });
1323
1461
  setPasskeys(rows);
1324
1462
  } catch (err) {
1325
- setError(err instanceof Error ? err.message : "Failed to load passkeys");
1463
+ setError(err instanceof node.AuthioError ? err.message : "We couldn't load your passkeys. Please refresh the page and try again.");
1326
1464
  setPasskeys([]);
1327
1465
  } finally {
1328
1466
  setLoading(false);
@@ -1340,7 +1478,7 @@ function usePasskeys() {
1340
1478
  const rename = react.useCallback(
1341
1479
  async (credentialId, nickname) => {
1342
1480
  const token = await ctx.getAccessToken();
1343
- if (!token) throw new Error("Not signed in");
1481
+ if (!token) throw notSignedIn();
1344
1482
  await renamePasskey(
1345
1483
  {
1346
1484
  apiUrl: ctx.apiUrl,
@@ -1358,7 +1496,7 @@ function usePasskeys() {
1358
1496
  const revoke = react.useCallback(
1359
1497
  async (credentialId) => {
1360
1498
  const token = await ctx.getAccessToken();
1361
- if (!token) throw new Error("Not signed in");
1499
+ if (!token) throw notSignedIn();
1362
1500
  await revokePasskey(
1363
1501
  {
1364
1502
  apiUrl: ctx.apiUrl,
@@ -1376,7 +1514,7 @@ function usePasskeys() {
1376
1514
  async (opts) => {
1377
1515
  const token = await ctx.getAccessToken();
1378
1516
  const email = ctx.user?.email;
1379
- if (!token || !email) throw new Error("Not signed in");
1517
+ if (!token || !email) throw notSignedIn();
1380
1518
  await enrollPasskey({
1381
1519
  apiUrl: ctx.apiUrl,
1382
1520
  projectId: ctx.projectId,
@@ -1414,7 +1552,7 @@ function PasskeyManager({
1414
1552
  try {
1415
1553
  await rename(id, nickname);
1416
1554
  } catch (err) {
1417
- setActionError(err instanceof Error ? err.message : "Rename failed");
1555
+ setActionError(err instanceof node.AuthioError ? err.message : "We couldn't rename that passkey. Please try again.");
1418
1556
  } finally {
1419
1557
  setBusyId(null);
1420
1558
  }
@@ -1425,7 +1563,7 @@ function PasskeyManager({
1425
1563
  try {
1426
1564
  await revoke(id);
1427
1565
  } catch (err) {
1428
- setActionError(err instanceof Error ? err.message : "Revoke failed");
1566
+ setActionError(err instanceof node.AuthioError ? err.message : "We couldn't remove that passkey. Please try again.");
1429
1567
  } finally {
1430
1568
  setBusyId(null);
1431
1569
  }
@@ -1437,7 +1575,7 @@ function PasskeyManager({
1437
1575
  await enroll({ returnUrl: enrollReturnUrl, next: enrollNext });
1438
1576
  } catch (err) {
1439
1577
  setEnrolling(false);
1440
- setActionError(err instanceof Error ? err.message : "Could not start enrollment");
1578
+ setActionError(err instanceof node.AuthioError ? err.message : "We couldn't start passkey setup. Please try again.");
1441
1579
  }
1442
1580
  }
1443
1581
  return /* @__PURE__ */ jsxRuntime.jsxs("section", { className, "aria-labelledby": "authio-passkey-manager-title", children: [
@@ -1558,9 +1696,12 @@ Object.defineProperty(exports, "AuthioError", {
1558
1696
  enumerable: true,
1559
1697
  get: function () { return node.AuthioError; }
1560
1698
  });
1699
+ exports.AUTHIO_MESSAGES = AUTHIO_MESSAGES;
1561
1700
  exports.ActivityTracker = ActivityTracker;
1562
1701
  exports.AuthioContext = AuthioContext;
1563
1702
  exports.AuthioProvider = AuthioProvider;
1703
+ exports.AuthioSignInDeniedError = AuthioSignInDeniedError;
1704
+ exports.AuthioStepUpRequiredError = AuthioStepUpRequiredError;
1564
1705
  exports.DEVICE_SIGNALS_HEADER = DEVICE_SIGNALS_HEADER;
1565
1706
  exports.PasskeyManager = PasskeyManager;
1566
1707
  exports.RedirectToSignIn = RedirectToSignIn;
@@ -1575,6 +1716,7 @@ exports.collectDeviceSignals = collectDeviceSignals;
1575
1716
  exports.deviceSignalsExtraHeaders = deviceSignalsExtraHeaders;
1576
1717
  exports.encodeDeviceSignalsHeader = encodeDeviceSignalsHeader;
1577
1718
  exports.enrollPasskey = enrollPasskey;
1719
+ exports.isStepUpRequired = isStepUpRequired;
1578
1720
  exports.listPasskeys = listPasskeys;
1579
1721
  exports.mintPasskeyRegisterIntent = mintPasskeyRegisterIntent;
1580
1722
  exports.renamePasskey = renamePasskey;