cauthy-auth 0.25.0 → 0.26.0

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.mjs CHANGED
@@ -1195,6 +1195,7 @@ function createCauthy(given = {}) {
1195
1195
  "/me/mfa/phone/remove",
1196
1196
  "/sign-in/mfa/methods",
1197
1197
  "/sign-in/mfa/send",
1198
+ "/sign-in/mfa/email",
1198
1199
  "/sign-in/mfa/push",
1199
1200
  "/sign-in/mfa/push/events",
1200
1201
  "/sign-in/mfa/push/finish",
@@ -1488,7 +1489,8 @@ function createCauthy(given = {}) {
1488
1489
  if (res.error) return problem(res.status, res.error.code, res.error.message);
1489
1490
  if (res.data?.mfa_required === true) {
1490
1491
  const step = { kind: "mfa", token: String(res.data.mfa_token ?? ""), returnTo: afterSignIn };
1491
- return json({ status: "mfa_required" }, 200, new Headers({ "set-cookie": writeCookie(stepCookie, await seal(step, await key), attrs(request, STEP_SECONDS)) }));
1492
+ const how = res.data.mfa_method === "email" ? { method: "email" } : {};
1493
+ return json({ status: "mfa_required", ...how }, 200, new Headers({ "set-cookie": writeCookie(stepCookie, await seal(step, await key), attrs(request, STEP_SECONDS)) }));
1492
1494
  }
1493
1495
  return signedIn(request, res.data);
1494
1496
  }
@@ -1515,7 +1517,7 @@ function createCauthy(given = {}) {
1515
1517
  if (res.error) return problem(res.status, res.error.code, res.error.message);
1516
1518
  return signedIn(request, res.data, [writeCookie(stepCookie, "", attrs(request, 0))]);
1517
1519
  }
1518
- if (route === "/sign-in/mfa/methods" || route === "/sign-in/mfa/send") {
1520
+ if (route === "/sign-in/mfa/methods" || route === "/sign-in/mfa/send" || route === "/sign-in/mfa/email") {
1519
1521
  const sealed = readCookies(request.headers.get("cookie")).get(stepCookie);
1520
1522
  const step = sealed ? await unseal(sealed, await key) : null;
1521
1523
  if (step === null || step.kind !== "mfa") return problem(400, "step_expired", "Sign in again: the code was asked for too long ago.");
@@ -1524,13 +1526,20 @@ function createCauthy(given = {}) {
1524
1526
  if (res2.error) return problem(res2.status, res2.error.code, res2.error.message);
1525
1527
  const p = res2.data?.phone;
1526
1528
  const push = res2.data?.push;
1529
+ const mail = res2.data?.email;
1527
1530
  return json({
1528
1531
  status: "ok",
1529
1532
  totp: res2.data?.totp === true,
1530
1533
  phone: p ? { number: String(p.number ?? ""), channel: String(p.channel ?? "sms") } : null,
1531
- push: push ? { devices: Number(push.devices ?? 0) } : null
1534
+ push: push ? { devices: Number(push.devices ?? 0) } : null,
1535
+ email: mail ? { to: String(mail.to ?? "") } : null
1532
1536
  });
1533
1537
  }
1538
+ if (route === "/sign-in/mfa/email") {
1539
+ const res2 = await ask(request, "POST", "/v1/auth/mfa/email", { mfa_token: step.token });
1540
+ if (res2.error) return problem(res2.status, res2.error.code, res2.error.message);
1541
+ return json({ status: "sent", sentTo: String(res2.data?.sent_to ?? "") });
1542
+ }
1534
1543
  const res = await ask(request, "POST", "/v1/auth/mfa/send", { mfa_token: step.token });
1535
1544
  if (res.error) return problem(res.status, res.error.code, res.error.message);
1536
1545
  return json({ status: "sent", sentTo: String(res.data?.sent_to ?? ""), channel: String(res.data?.channel ?? "sms") });