@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 +35 -0
- package/README.md +37 -1
- package/dist/index.cjs +220 -78
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +102 -11
- package/dist/index.d.ts +102 -11
- package/dist/index.js +217 -79
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/PasskeyManager.tsx +4 -3
- package/src/errors.ts +239 -17
- package/src/fetch.ts +23 -12
- package/src/index.ts +8 -1
- package/src/lobby-context.ts +8 -0
- package/src/passkeys.ts +18 -8
- package/src/provider.tsx +2 -1
- package/src/sign-in.ts +122 -75
- package/src/usePasskeys.ts +13 -4
- package/src/version.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -5,32 +5,146 @@ import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
|
5
5
|
import { startRegistration } from '@simplewebauthn/browser';
|
|
6
6
|
|
|
7
7
|
// src/provider.tsx
|
|
8
|
+
var AUTHIO_MESSAGES = {
|
|
9
|
+
network_error: "We couldn't reach the sign-in service. Check your internet connection and try again.",
|
|
10
|
+
timeout: "The sign-in service took too long to respond. Please try again.",
|
|
11
|
+
aborted: "The request was cancelled before it finished. Please try again.",
|
|
12
|
+
invalid_response: "We couldn't finish signing you in because the sign-in service sent an unexpected response. Please try again.",
|
|
13
|
+
step_up_required: "For your security, we need one more check before signing you in.",
|
|
14
|
+
sign_in_denied: "We couldn't sign you in. If you think this is a mistake, contact support or your administrator.",
|
|
15
|
+
rate_limited: "Too many attempts. Please wait a moment and try again.",
|
|
16
|
+
server_error: "Something went wrong on our side. Please try again in a moment.",
|
|
17
|
+
request_failed: "We couldn't complete that request. Please try again.",
|
|
18
|
+
webauthn_cancelled: "Passkey sign-in was cancelled or timed out. Please try again.",
|
|
19
|
+
webauthn_registration_cancelled: "Passkey setup was cancelled or timed out. Please try again.",
|
|
20
|
+
webauthn_already_registered: "This device already has a passkey for your account.",
|
|
21
|
+
webauthn_unsupported: "This browser doesn't support passkeys. Try a different browser, or sign in another way.",
|
|
22
|
+
not_signed_in: "You need to be signed in to do that. Please sign in and try again.",
|
|
23
|
+
token_rejected: "We couldn't verify your sign-in. Please sign in again."
|
|
24
|
+
};
|
|
25
|
+
function withCause(err, cause) {
|
|
26
|
+
if (cause !== void 0) {
|
|
27
|
+
Object.defineProperty(err, "cause", {
|
|
28
|
+
value: cause,
|
|
29
|
+
enumerable: false,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return err;
|
|
35
|
+
}
|
|
8
36
|
function wrapFetchError(err, fallbackCode = "network_error") {
|
|
9
37
|
if (err instanceof AuthioError) return err;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
38
|
+
const e = err && typeof err === "object" ? err : {};
|
|
39
|
+
const name = typeof e.name === "string" ? e.name : "";
|
|
40
|
+
const rawMessage = typeof e.message === "string" ? e.message : "";
|
|
41
|
+
const isTimeout = name === "TimeoutError" || /timed? ?out/i.test(rawMessage);
|
|
42
|
+
if (isTimeout) {
|
|
43
|
+
return withCause(
|
|
44
|
+
new AuthioError({
|
|
45
|
+
code: "timeout",
|
|
46
|
+
message: AUTHIO_MESSAGES.timeout,
|
|
47
|
+
status: 0
|
|
48
|
+
}),
|
|
49
|
+
err
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
if (name === "AbortError") {
|
|
53
|
+
return withCause(
|
|
54
|
+
new AuthioError({
|
|
55
|
+
code: "aborted",
|
|
56
|
+
message: AUTHIO_MESSAGES.aborted,
|
|
57
|
+
status: 0
|
|
58
|
+
}),
|
|
59
|
+
err
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
const message = fallbackCode === "network_error" ? AUTHIO_MESSAGES.network_error : AUTHIO_MESSAGES.request_failed;
|
|
63
|
+
return withCause(
|
|
64
|
+
new AuthioError({ code: fallbackCode, message, status: 0 }),
|
|
65
|
+
err
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
function messageForStatus(status) {
|
|
69
|
+
if (status === 429) return AUTHIO_MESSAGES.rate_limited;
|
|
70
|
+
if (status >= 500) return AUTHIO_MESSAGES.server_error;
|
|
71
|
+
return AUTHIO_MESSAGES.request_failed;
|
|
72
|
+
}
|
|
73
|
+
var AuthioStepUpRequiredError = class extends AuthioError {
|
|
74
|
+
stepUpUrl;
|
|
75
|
+
challengeId;
|
|
76
|
+
requiredMethod;
|
|
77
|
+
reasons;
|
|
78
|
+
enrollmentRequired;
|
|
79
|
+
/** auth-core's own explanation of the step, when it sent one. */
|
|
80
|
+
serverMessage;
|
|
81
|
+
constructor(opts) {
|
|
82
|
+
super({
|
|
83
|
+
code: "step_up_required",
|
|
84
|
+
message: AUTHIO_MESSAGES.step_up_required,
|
|
85
|
+
status: opts.status,
|
|
86
|
+
requestId: opts.requestId
|
|
15
87
|
});
|
|
88
|
+
this.name = "AuthioStepUpRequiredError";
|
|
89
|
+
this.stepUpUrl = opts.stepUpUrl;
|
|
90
|
+
this.challengeId = opts.challengeId;
|
|
91
|
+
this.requiredMethod = opts.requiredMethod;
|
|
92
|
+
this.reasons = opts.reasons ?? [];
|
|
93
|
+
this.enrollmentRequired = Boolean(opts.enrollmentRequired);
|
|
94
|
+
this.serverMessage = opts.serverMessage;
|
|
16
95
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
96
|
+
};
|
|
97
|
+
var AuthioSignInDeniedError = class extends AuthioError {
|
|
98
|
+
denyCode;
|
|
99
|
+
reasons;
|
|
100
|
+
constructor(opts) {
|
|
101
|
+
super({
|
|
102
|
+
code: "sign_in_denied",
|
|
103
|
+
message: nonEmpty(opts.message) ?? AUTHIO_MESSAGES.sign_in_denied,
|
|
104
|
+
status: opts.status,
|
|
105
|
+
requestId: opts.requestId
|
|
22
106
|
});
|
|
107
|
+
this.name = "AuthioSignInDeniedError";
|
|
108
|
+
this.denyCode = opts.denyCode;
|
|
109
|
+
this.reasons = opts.reasons ?? [];
|
|
23
110
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
111
|
+
};
|
|
112
|
+
function isStepUpRequired(err) {
|
|
113
|
+
return err instanceof AuthioStepUpRequiredError;
|
|
114
|
+
}
|
|
115
|
+
function riskDecisionError(body, status) {
|
|
116
|
+
if (!body || typeof body !== "object") return null;
|
|
117
|
+
const decision = typeof body.decision === "string" ? body.decision : "";
|
|
118
|
+
const reasons = Array.isArray(body.reasons) ? body.reasons.filter((r) => typeof r === "string") : [];
|
|
119
|
+
if (decision === "step_up" || body.code === "step_up_required") {
|
|
120
|
+
return new AuthioStepUpRequiredError({
|
|
121
|
+
status,
|
|
122
|
+
stepUpUrl: nonEmpty(body.step_up_url),
|
|
123
|
+
challengeId: nonEmpty(body.challenge_id),
|
|
124
|
+
requiredMethod: nonEmpty(body.required_method),
|
|
125
|
+
reasons,
|
|
126
|
+
enrollmentRequired: body.enrollment_required === true,
|
|
127
|
+
serverMessage: nonEmpty(body.message),
|
|
128
|
+
requestId: body.request_id
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
if (decision === "block" || decision === "deny") {
|
|
132
|
+
return new AuthioSignInDeniedError({
|
|
133
|
+
status,
|
|
134
|
+
message: body.message,
|
|
135
|
+
denyCode: nonEmpty(body.code) ?? nonEmpty(body.error),
|
|
136
|
+
reasons,
|
|
137
|
+
requestId: body.request_id
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
function nonEmpty(v) {
|
|
143
|
+
return typeof v === "string" && v.trim() !== "" ? v : void 0;
|
|
30
144
|
}
|
|
31
145
|
|
|
32
146
|
// src/version.ts
|
|
33
|
-
var SDK_VERSION = "0.3.
|
|
147
|
+
var SDK_VERSION = "0.3.1";
|
|
34
148
|
var SDK_USER_AGENT = `react/${SDK_VERSION}`;
|
|
35
149
|
|
|
36
150
|
// src/fetch.ts
|
|
@@ -75,10 +189,14 @@ async function authioFetch(opts) {
|
|
|
75
189
|
if (opts.signal) opts.signal.removeEventListener("abort", onCallerAbort);
|
|
76
190
|
}
|
|
77
191
|
if (!res.ok) {
|
|
78
|
-
const
|
|
192
|
+
const raw = await res.json().catch(() => ({}));
|
|
193
|
+
const body = raw && typeof raw === "object" ? raw : {};
|
|
194
|
+
const risk = riskDecisionError(body, res.status);
|
|
195
|
+
if (risk) throw risk;
|
|
196
|
+
const message = typeof body.message === "string" && body.message.trim() !== "" ? body.message : messageForStatus(res.status);
|
|
79
197
|
throw new AuthioError({
|
|
80
198
|
code: body.code ?? body.error ?? "request_failed",
|
|
81
|
-
message
|
|
199
|
+
message,
|
|
82
200
|
status: res.status,
|
|
83
201
|
requestId: body.request_id
|
|
84
202
|
});
|
|
@@ -91,7 +209,7 @@ async function authioFetch(opts) {
|
|
|
91
209
|
} catch {
|
|
92
210
|
throw new AuthioError({
|
|
93
211
|
code: "invalid_response",
|
|
94
|
-
message:
|
|
212
|
+
message: AUTHIO_MESSAGES.invalid_response,
|
|
95
213
|
status: res.status
|
|
96
214
|
});
|
|
97
215
|
}
|
|
@@ -398,7 +516,8 @@ async function mintLobbySignInUrl(opts) {
|
|
|
398
516
|
project_id: opts.projectId,
|
|
399
517
|
redirect_uri: opts.redirectUri,
|
|
400
518
|
...opts.next ? { next: opts.next } : {},
|
|
401
|
-
...opts.organizationId ? { organization_id: opts.organizationId } : {}
|
|
519
|
+
...opts.organizationId ? { organization_id: opts.organizationId } : {},
|
|
520
|
+
...opts.xrayVisitorProof ? { xray_visitor_proof: opts.xrayVisitorProof } : {}
|
|
402
521
|
})
|
|
403
522
|
}
|
|
404
523
|
);
|
|
@@ -422,6 +541,9 @@ async function mintLobbySignInUrl(opts) {
|
|
|
422
541
|
if (opts.organizationId) {
|
|
423
542
|
target.searchParams.set("organization_id", opts.organizationId);
|
|
424
543
|
}
|
|
544
|
+
if (opts.xrayVisitorProof) {
|
|
545
|
+
target.searchParams.set("xray_visitor_proof", opts.xrayVisitorProof);
|
|
546
|
+
}
|
|
425
547
|
return target.toString();
|
|
426
548
|
}
|
|
427
549
|
|
|
@@ -802,7 +924,7 @@ function AuthioProvider(props) {
|
|
|
802
924
|
setStatus("unauthenticated");
|
|
803
925
|
throw new AuthioError({
|
|
804
926
|
code: "token_rejected",
|
|
805
|
-
message: "
|
|
927
|
+
message: "We couldn't verify your sign-in. Please sign in again.",
|
|
806
928
|
status: 0
|
|
807
929
|
});
|
|
808
930
|
}
|
|
@@ -981,24 +1103,51 @@ async function signInWithMagicLink(opts) {
|
|
|
981
1103
|
// auth-core's magic-link send reads the recipient as `destination`
|
|
982
1104
|
// (email or E.164), NOT `email`. See magiclink.go magicLinkSendReq.
|
|
983
1105
|
destination: opts.email,
|
|
984
|
-
redirect_uri: opts.redirectUri
|
|
1106
|
+
redirect_uri: opts.redirectUri,
|
|
1107
|
+
...opts.xrayVisitorProof ? { xray_visitor_proof: opts.xrayVisitorProof } : {}
|
|
985
1108
|
},
|
|
986
1109
|
signal: opts.signal,
|
|
987
1110
|
fetchImpl: opts.fetch
|
|
988
1111
|
});
|
|
989
1112
|
}
|
|
1113
|
+
function sessionFromResponse(res, status = 200) {
|
|
1114
|
+
const risk = riskDecisionError(res, status);
|
|
1115
|
+
if (risk) throw risk;
|
|
1116
|
+
const accessToken = res && typeof res.access_token === "string" ? res.access_token : "";
|
|
1117
|
+
const user = res && res.user && typeof res.user === "object" ? res.user : null;
|
|
1118
|
+
const userId = user && typeof user.id === "string" ? user.id : "";
|
|
1119
|
+
if (!res || !accessToken || !user || !userId) {
|
|
1120
|
+
throw new AuthioError({
|
|
1121
|
+
code: "invalid_response",
|
|
1122
|
+
message: AUTHIO_MESSAGES.invalid_response,
|
|
1123
|
+
status
|
|
1124
|
+
});
|
|
1125
|
+
}
|
|
1126
|
+
return {
|
|
1127
|
+
accessToken,
|
|
1128
|
+
refreshToken: typeof res.refresh_token === "string" ? res.refresh_token : void 0,
|
|
1129
|
+
sessionPolicy: coerceSessionPolicy(res.session_policy),
|
|
1130
|
+
user: {
|
|
1131
|
+
id: userId,
|
|
1132
|
+
email: typeof user.email === "string" ? user.email : "",
|
|
1133
|
+
emailVerified: Boolean(user.emailVerified ?? user.email_verified),
|
|
1134
|
+
name: user.name,
|
|
1135
|
+
avatarUrl: user.avatarUrl ?? user.avatar_url
|
|
1136
|
+
}
|
|
1137
|
+
};
|
|
1138
|
+
}
|
|
990
1139
|
async function signInWithPasskey(opts) {
|
|
991
1140
|
if (!isBrowser() || typeof navigator === "undefined") {
|
|
992
1141
|
throw new AuthioError({
|
|
993
1142
|
code: "not_in_browser",
|
|
994
|
-
message: "
|
|
1143
|
+
message: "Passkey sign-in only works in a web browser. Call signInWithPasskey from client-side code.",
|
|
995
1144
|
status: 0
|
|
996
1145
|
});
|
|
997
1146
|
}
|
|
998
1147
|
if (!navigator.credentials || !navigator.credentials.get) {
|
|
999
1148
|
throw new AuthioError({
|
|
1000
1149
|
code: "webauthn_unsupported",
|
|
1001
|
-
message:
|
|
1150
|
+
message: AUTHIO_MESSAGES.webauthn_unsupported,
|
|
1002
1151
|
status: 0
|
|
1003
1152
|
});
|
|
1004
1153
|
}
|
|
@@ -1011,6 +1160,13 @@ async function signInWithPasskey(opts) {
|
|
|
1011
1160
|
signal: opts.signal,
|
|
1012
1161
|
fetchImpl: opts.fetch
|
|
1013
1162
|
});
|
|
1163
|
+
if (!options || typeof options.challenge !== "string" || !options.challenge) {
|
|
1164
|
+
throw new AuthioError({
|
|
1165
|
+
code: "invalid_response",
|
|
1166
|
+
message: AUTHIO_MESSAGES.invalid_response,
|
|
1167
|
+
status: 200
|
|
1168
|
+
});
|
|
1169
|
+
}
|
|
1014
1170
|
const publicKey = {
|
|
1015
1171
|
challenge: base64UrlToBuffer(options.challenge),
|
|
1016
1172
|
rpId: options.rpId,
|
|
@@ -1029,16 +1185,18 @@ async function signInWithPasskey(opts) {
|
|
|
1029
1185
|
signal: opts.signal
|
|
1030
1186
|
});
|
|
1031
1187
|
} catch (err) {
|
|
1032
|
-
|
|
1188
|
+
const e = new AuthioError({
|
|
1033
1189
|
code: "webauthn_cancelled",
|
|
1034
|
-
message:
|
|
1190
|
+
message: AUTHIO_MESSAGES.webauthn_cancelled,
|
|
1035
1191
|
status: 0
|
|
1036
1192
|
});
|
|
1193
|
+
Object.defineProperty(e, "cause", { value: err, enumerable: false });
|
|
1194
|
+
throw e;
|
|
1037
1195
|
}
|
|
1038
1196
|
if (!credential) {
|
|
1039
1197
|
throw new AuthioError({
|
|
1040
1198
|
code: "webauthn_cancelled",
|
|
1041
|
-
message:
|
|
1199
|
+
message: AUTHIO_MESSAGES.webauthn_cancelled,
|
|
1042
1200
|
status: 0
|
|
1043
1201
|
});
|
|
1044
1202
|
}
|
|
@@ -1064,27 +1222,15 @@ async function signInWithPasskey(opts) {
|
|
|
1064
1222
|
body: {
|
|
1065
1223
|
credential: webauthnCredential,
|
|
1066
1224
|
...opts.next ? { next: opts.next } : {},
|
|
1067
|
-
...opts.organizationId ? { organization_id: opts.organizationId } : {}
|
|
1225
|
+
...opts.organizationId ? { organization_id: opts.organizationId } : {},
|
|
1226
|
+
...opts.xrayVisitorProof ? { xray_visitor_proof: opts.xrayVisitorProof } : {}
|
|
1068
1227
|
},
|
|
1069
1228
|
extraHeaders: deviceSignalsExtraHeaders(),
|
|
1070
1229
|
credentials: "include",
|
|
1071
1230
|
signal: opts.signal,
|
|
1072
1231
|
fetchImpl: opts.fetch
|
|
1073
1232
|
});
|
|
1074
|
-
return
|
|
1075
|
-
accessToken: verifyRes.access_token,
|
|
1076
|
-
refreshToken: verifyRes.refresh_token,
|
|
1077
|
-
sessionPolicy: coerceSessionPolicy(verifyRes.session_policy),
|
|
1078
|
-
user: {
|
|
1079
|
-
id: verifyRes.user.id,
|
|
1080
|
-
email: verifyRes.user.email,
|
|
1081
|
-
emailVerified: Boolean(
|
|
1082
|
-
verifyRes.user.emailVerified ?? verifyRes.user.email_verified
|
|
1083
|
-
),
|
|
1084
|
-
name: verifyRes.user.name,
|
|
1085
|
-
avatarUrl: verifyRes.user.avatarUrl ?? verifyRes.user.avatar_url
|
|
1086
|
-
}
|
|
1087
|
-
};
|
|
1233
|
+
return sessionFromResponse(verifyRes);
|
|
1088
1234
|
}
|
|
1089
1235
|
async function sendEmailOtp(opts) {
|
|
1090
1236
|
await authioFetch({
|
|
@@ -1096,7 +1242,8 @@ async function sendEmailOtp(opts) {
|
|
|
1096
1242
|
email: opts.email,
|
|
1097
1243
|
...opts.redirectUri ? { redirect_uri: opts.redirectUri } : {},
|
|
1098
1244
|
...opts.next ? { next: opts.next } : {},
|
|
1099
|
-
...opts.organizationId ? { organization_id: opts.organizationId } : {}
|
|
1245
|
+
...opts.organizationId ? { organization_id: opts.organizationId } : {},
|
|
1246
|
+
...opts.xrayVisitorProof ? { xray_visitor_proof: opts.xrayVisitorProof } : {}
|
|
1100
1247
|
},
|
|
1101
1248
|
signal: opts.signal,
|
|
1102
1249
|
fetchImpl: opts.fetch
|
|
@@ -1115,33 +1262,14 @@ async function verifyEmailOtp(opts) {
|
|
|
1115
1262
|
...opts.next ? { next: opts.next } : {},
|
|
1116
1263
|
...opts.organizationId ? { organization_id: opts.organizationId } : {},
|
|
1117
1264
|
...opts.clientLocation ? { client_location: opts.clientLocation } : {},
|
|
1118
|
-
...opts.deviceSignals ? { device_signals: opts.deviceSignals } : {}
|
|
1265
|
+
...opts.deviceSignals ? { device_signals: opts.deviceSignals } : {},
|
|
1266
|
+
...opts.xrayVisitorProof ? { xray_visitor_proof: opts.xrayVisitorProof } : {}
|
|
1119
1267
|
},
|
|
1120
1268
|
credentials: "include",
|
|
1121
1269
|
signal: opts.signal,
|
|
1122
1270
|
fetchImpl: opts.fetch
|
|
1123
1271
|
});
|
|
1124
|
-
|
|
1125
|
-
throw new AuthioError({
|
|
1126
|
-
code: "step_up_required",
|
|
1127
|
-
message: "Additional verification is required. Complete the step-up challenge on the hosted sign-in page.",
|
|
1128
|
-
status: 200
|
|
1129
|
-
});
|
|
1130
|
-
}
|
|
1131
|
-
return {
|
|
1132
|
-
accessToken: verifyRes.access_token,
|
|
1133
|
-
refreshToken: verifyRes.refresh_token,
|
|
1134
|
-
sessionPolicy: coerceSessionPolicy(verifyRes.session_policy),
|
|
1135
|
-
user: {
|
|
1136
|
-
id: verifyRes.user.id,
|
|
1137
|
-
email: verifyRes.user.email,
|
|
1138
|
-
emailVerified: Boolean(
|
|
1139
|
-
verifyRes.user.emailVerified ?? verifyRes.user.email_verified
|
|
1140
|
-
),
|
|
1141
|
-
name: verifyRes.user.name,
|
|
1142
|
-
avatarUrl: verifyRes.user.avatarUrl ?? verifyRes.user.avatar_url
|
|
1143
|
-
}
|
|
1144
|
-
};
|
|
1272
|
+
return sessionFromResponse(verifyRes);
|
|
1145
1273
|
}
|
|
1146
1274
|
function base64UrlToBuffer(b64u) {
|
|
1147
1275
|
const padded = b64u.replace(/-/g, "+").replace(/_/g, "/").padEnd(b64u.length + (4 - b64u.length % 4) % 4, "=");
|
|
@@ -1203,7 +1331,7 @@ async function enrollPasskey(opts) {
|
|
|
1203
1331
|
if (!isBrowser()) {
|
|
1204
1332
|
throw new AuthioError({
|
|
1205
1333
|
code: "not_in_browser",
|
|
1206
|
-
message: "
|
|
1334
|
+
message: "Passkey setup only works in a web browser. Call enrollPasskey from client-side code.",
|
|
1207
1335
|
status: 0
|
|
1208
1336
|
});
|
|
1209
1337
|
}
|
|
@@ -1223,7 +1351,7 @@ async function addPasskey(opts) {
|
|
|
1223
1351
|
if (!isBrowser()) {
|
|
1224
1352
|
throw new AuthioError({
|
|
1225
1353
|
code: "not_in_browser",
|
|
1226
|
-
message: "
|
|
1354
|
+
message: "Passkey setup only works in a web browser. Call addPasskey from client-side code.",
|
|
1227
1355
|
status: 0
|
|
1228
1356
|
});
|
|
1229
1357
|
}
|
|
@@ -1243,11 +1371,14 @@ async function addPasskey(opts) {
|
|
|
1243
1371
|
try {
|
|
1244
1372
|
attestation = await startRegistration({ optionsJSON: options });
|
|
1245
1373
|
} catch (err) {
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1374
|
+
const already = err instanceof Error && (err.name === "InvalidStateError" || err.code === "ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED");
|
|
1375
|
+
const e = new AuthioError({
|
|
1376
|
+
code: already ? "webauthn_already_registered" : "webauthn_cancelled",
|
|
1377
|
+
message: already ? AUTHIO_MESSAGES.webauthn_already_registered : AUTHIO_MESSAGES.webauthn_registration_cancelled,
|
|
1249
1378
|
status: 0
|
|
1250
1379
|
});
|
|
1380
|
+
Object.defineProperty(e, "cause", { value: err, enumerable: false });
|
|
1381
|
+
throw e;
|
|
1251
1382
|
}
|
|
1252
1383
|
await authioFetch({
|
|
1253
1384
|
apiUrl: opts.apiUrl,
|
|
@@ -1294,6 +1425,13 @@ async function revokePasskey(opts, credentialId) {
|
|
|
1294
1425
|
extraHeaders: bearerHeaders(opts.accessToken)
|
|
1295
1426
|
});
|
|
1296
1427
|
}
|
|
1428
|
+
function notSignedIn() {
|
|
1429
|
+
return new AuthioError({
|
|
1430
|
+
code: "not_signed_in",
|
|
1431
|
+
message: AUTHIO_MESSAGES.not_signed_in,
|
|
1432
|
+
status: 401
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1297
1435
|
function usePasskeys() {
|
|
1298
1436
|
const ctx = useAuthio();
|
|
1299
1437
|
const [passkeys, setPasskeys] = useState([]);
|
|
@@ -1321,7 +1459,7 @@ function usePasskeys() {
|
|
|
1321
1459
|
});
|
|
1322
1460
|
setPasskeys(rows);
|
|
1323
1461
|
} catch (err) {
|
|
1324
|
-
setError(err instanceof
|
|
1462
|
+
setError(err instanceof AuthioError ? err.message : "We couldn't load your passkeys. Please refresh the page and try again.");
|
|
1325
1463
|
setPasskeys([]);
|
|
1326
1464
|
} finally {
|
|
1327
1465
|
setLoading(false);
|
|
@@ -1339,7 +1477,7 @@ function usePasskeys() {
|
|
|
1339
1477
|
const rename = useCallback(
|
|
1340
1478
|
async (credentialId, nickname) => {
|
|
1341
1479
|
const token = await ctx.getAccessToken();
|
|
1342
|
-
if (!token) throw
|
|
1480
|
+
if (!token) throw notSignedIn();
|
|
1343
1481
|
await renamePasskey(
|
|
1344
1482
|
{
|
|
1345
1483
|
apiUrl: ctx.apiUrl,
|
|
@@ -1357,7 +1495,7 @@ function usePasskeys() {
|
|
|
1357
1495
|
const revoke = useCallback(
|
|
1358
1496
|
async (credentialId) => {
|
|
1359
1497
|
const token = await ctx.getAccessToken();
|
|
1360
|
-
if (!token) throw
|
|
1498
|
+
if (!token) throw notSignedIn();
|
|
1361
1499
|
await revokePasskey(
|
|
1362
1500
|
{
|
|
1363
1501
|
apiUrl: ctx.apiUrl,
|
|
@@ -1375,7 +1513,7 @@ function usePasskeys() {
|
|
|
1375
1513
|
async (opts) => {
|
|
1376
1514
|
const token = await ctx.getAccessToken();
|
|
1377
1515
|
const email = ctx.user?.email;
|
|
1378
|
-
if (!token || !email) throw
|
|
1516
|
+
if (!token || !email) throw notSignedIn();
|
|
1379
1517
|
await enrollPasskey({
|
|
1380
1518
|
apiUrl: ctx.apiUrl,
|
|
1381
1519
|
projectId: ctx.projectId,
|
|
@@ -1413,7 +1551,7 @@ function PasskeyManager({
|
|
|
1413
1551
|
try {
|
|
1414
1552
|
await rename(id, nickname);
|
|
1415
1553
|
} catch (err) {
|
|
1416
|
-
setActionError(err instanceof
|
|
1554
|
+
setActionError(err instanceof AuthioError ? err.message : "We couldn't rename that passkey. Please try again.");
|
|
1417
1555
|
} finally {
|
|
1418
1556
|
setBusyId(null);
|
|
1419
1557
|
}
|
|
@@ -1424,7 +1562,7 @@ function PasskeyManager({
|
|
|
1424
1562
|
try {
|
|
1425
1563
|
await revoke(id);
|
|
1426
1564
|
} catch (err) {
|
|
1427
|
-
setActionError(err instanceof
|
|
1565
|
+
setActionError(err instanceof AuthioError ? err.message : "We couldn't remove that passkey. Please try again.");
|
|
1428
1566
|
} finally {
|
|
1429
1567
|
setBusyId(null);
|
|
1430
1568
|
}
|
|
@@ -1436,7 +1574,7 @@ function PasskeyManager({
|
|
|
1436
1574
|
await enroll({ returnUrl: enrollReturnUrl, next: enrollNext });
|
|
1437
1575
|
} catch (err) {
|
|
1438
1576
|
setEnrolling(false);
|
|
1439
|
-
setActionError(err instanceof
|
|
1577
|
+
setActionError(err instanceof AuthioError ? err.message : "We couldn't start passkey setup. Please try again.");
|
|
1440
1578
|
}
|
|
1441
1579
|
}
|
|
1442
1580
|
return /* @__PURE__ */ jsxs("section", { className, "aria-labelledby": "authio-passkey-manager-title", children: [
|
|
@@ -1553,6 +1691,6 @@ async function verifyLocate(_opts) {
|
|
|
1553
1691
|
throw new Error(VERIFY_LOCATE_BACKEND_ONLY);
|
|
1554
1692
|
}
|
|
1555
1693
|
|
|
1556
|
-
export { ActivityTracker, AuthioContext, AuthioProvider, DEVICE_SIGNALS_HEADER, PasskeyManager, RedirectToSignIn, SignedIn, SignedOut, addPasskey, buildEnrollPasskeyUrl, canEnrollPasskeyEmbedded, captureClientLocation, coerceSessionPolicy, collectDeviceSignals, deviceSignalsExtraHeaders, encodeDeviceSignalsHeader, enrollPasskey, listPasskeys, mintPasskeyRegisterIntent, renamePasskey, revokePasskey, sendEmailOtp, signInOrigin, signInWithMagicLink, signInWithPasskey, useAuthio, useAuthioRequired, usePasskeys, verifyEmailOtp, verifyLocate, wrapFetchError };
|
|
1694
|
+
export { AUTHIO_MESSAGES, ActivityTracker, AuthioContext, AuthioProvider, AuthioSignInDeniedError, AuthioStepUpRequiredError, DEVICE_SIGNALS_HEADER, PasskeyManager, RedirectToSignIn, SignedIn, SignedOut, addPasskey, buildEnrollPasskeyUrl, canEnrollPasskeyEmbedded, captureClientLocation, coerceSessionPolicy, collectDeviceSignals, deviceSignalsExtraHeaders, encodeDeviceSignalsHeader, enrollPasskey, isStepUpRequired, listPasskeys, mintPasskeyRegisterIntent, renamePasskey, revokePasskey, sendEmailOtp, signInOrigin, signInWithMagicLink, signInWithPasskey, useAuthio, useAuthioRequired, usePasskeys, verifyEmailOtp, verifyLocate, wrapFetchError };
|
|
1557
1695
|
//# sourceMappingURL=index.js.map
|
|
1558
1696
|
//# sourceMappingURL=index.js.map
|