@orangecheck/auth-client 2.1.0 → 2.1.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/index.d.mts +17 -5
- package/dist/index.d.ts +17 -5
- package/dist/index.js +42 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1279,12 +1279,21 @@ function useWebAuthnRegister(opts) {
|
|
|
1279
1279
|
});
|
|
1280
1280
|
const optsBody = await optsRes.json();
|
|
1281
1281
|
if (!optsRes.ok || !optsBody.ok || !optsBody.options || !optsBody.challenge_token) {
|
|
1282
|
-
|
|
1282
|
+
const reason = optsBody.reason ?? `options_failed_${optsRes.status}`;
|
|
1283
|
+
setError(new Error(reason));
|
|
1284
|
+
setStatus("error");
|
|
1285
|
+
return { ok: false, reason };
|
|
1283
1286
|
}
|
|
1284
1287
|
setStatus("authenticating");
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
+
let attestation;
|
|
1289
|
+
try {
|
|
1290
|
+
attestation = await startRegistration({ optionsJSON: optsBody.options });
|
|
1291
|
+
} catch (e) {
|
|
1292
|
+
const reason = isAbortError(e) ? "cancelled" : e.message;
|
|
1293
|
+
setError(new Error(reason));
|
|
1294
|
+
setStatus("error");
|
|
1295
|
+
return { ok: false, reason };
|
|
1296
|
+
}
|
|
1288
1297
|
setStatus("verifying");
|
|
1289
1298
|
const verifyRes = await fetch(`${authOrigin}/api/auth/webauthn/register/verify`, {
|
|
1290
1299
|
method: "POST",
|
|
@@ -1298,18 +1307,18 @@ function useWebAuthnRegister(opts) {
|
|
|
1298
1307
|
});
|
|
1299
1308
|
const verifyBody = await verifyRes.json();
|
|
1300
1309
|
if (!verifyRes.ok || !verifyBody.ok || !verifyBody.credential) {
|
|
1301
|
-
|
|
1310
|
+
const reason = verifyBody.reason ?? `verify_failed_${verifyRes.status}`;
|
|
1311
|
+
setError(new Error(reason));
|
|
1312
|
+
setStatus("error");
|
|
1313
|
+
return { ok: false, reason };
|
|
1302
1314
|
}
|
|
1303
1315
|
setStatus("success");
|
|
1304
|
-
return verifyBody.credential;
|
|
1316
|
+
return { ok: true, credential: verifyBody.credential };
|
|
1305
1317
|
} catch (e) {
|
|
1306
|
-
const
|
|
1307
|
-
setError(
|
|
1318
|
+
const reason = e instanceof Error ? e.message : String(e);
|
|
1319
|
+
setError(new Error(reason));
|
|
1308
1320
|
setStatus("error");
|
|
1309
|
-
|
|
1310
|
-
setError(new Error("cancelled"));
|
|
1311
|
-
}
|
|
1312
|
-
return null;
|
|
1321
|
+
return { ok: false, reason };
|
|
1313
1322
|
}
|
|
1314
1323
|
},
|
|
1315
1324
|
[authOrigin]
|
|
@@ -1421,12 +1430,21 @@ function useStepUpAuth(opts) {
|
|
|
1421
1430
|
});
|
|
1422
1431
|
const optsBody = await optsRes.json();
|
|
1423
1432
|
if (!optsRes.ok || !optsBody.ok || !optsBody.options || !optsBody.challenge_token) {
|
|
1424
|
-
|
|
1433
|
+
const reason = optsBody.reason ?? `options_failed_${optsRes.status}`;
|
|
1434
|
+
setError(new Error(reason));
|
|
1435
|
+
setStatus("error");
|
|
1436
|
+
return { ok: false, reason };
|
|
1425
1437
|
}
|
|
1426
1438
|
setStatus("authenticating");
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1439
|
+
let assertion;
|
|
1440
|
+
try {
|
|
1441
|
+
assertion = await startAuthentication({ optionsJSON: optsBody.options });
|
|
1442
|
+
} catch (e) {
|
|
1443
|
+
const reason = isAbortError(e) ? "cancelled" : e.message;
|
|
1444
|
+
setError(new Error(reason));
|
|
1445
|
+
setStatus("error");
|
|
1446
|
+
return { ok: false, reason };
|
|
1447
|
+
}
|
|
1430
1448
|
setStatus("verifying");
|
|
1431
1449
|
const verifyRes = await fetch(
|
|
1432
1450
|
`${authOrigin}/api/auth/webauthn/assertion/verify`,
|
|
@@ -1442,16 +1460,19 @@ function useStepUpAuth(opts) {
|
|
|
1442
1460
|
);
|
|
1443
1461
|
const verifyBody = await verifyRes.json();
|
|
1444
1462
|
if (!verifyRes.ok || !verifyBody.ok || typeof verifyBody.step_up_at !== "number") {
|
|
1445
|
-
|
|
1463
|
+
const reason = verifyBody.reason ?? `verify_failed_${verifyRes.status}`;
|
|
1464
|
+
setError(new Error(reason));
|
|
1465
|
+
setStatus("error");
|
|
1466
|
+
return { ok: false, reason };
|
|
1446
1467
|
}
|
|
1447
1468
|
await refresh();
|
|
1448
1469
|
setStatus("success");
|
|
1449
|
-
return { step_up_at: verifyBody.step_up_at };
|
|
1470
|
+
return { ok: true, step_up_at: verifyBody.step_up_at };
|
|
1450
1471
|
} catch (e) {
|
|
1451
|
-
const
|
|
1452
|
-
setError(
|
|
1472
|
+
const reason = e instanceof Error ? e.message : String(e);
|
|
1473
|
+
setError(new Error(reason));
|
|
1453
1474
|
setStatus("error");
|
|
1454
|
-
return
|
|
1475
|
+
return { ok: false, reason };
|
|
1455
1476
|
}
|
|
1456
1477
|
},
|
|
1457
1478
|
[authOrigin, refresh]
|