cauthy-auth 0.17.0 → 0.19.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/react.mjs CHANGED
@@ -272,7 +272,8 @@ function createAuthClient(options = {}) {
272
272
  async passkey(o) {
273
273
  const m = await methods();
274
274
  if (m.passkeyHere && canUsePasskeys()) {
275
- const r = await ceremony("/sign-in/passkey/begin", "/sign-in/passkey/finish", {}, getPasskey);
275
+ const email = o?.email?.trim() ?? "";
276
+ const r = await ceremony("/sign-in/passkey/begin", "/sign-in/passkey/finish", email !== "" && checkEmail(email) === null ? { email } : {}, getPasskey);
276
277
  if (r.ok || r.error.code !== "passkey_unavailable" || !m.passkeyOnCauthy) return r;
277
278
  } else if (!m.passkeyOnCauthy) {
278
279
  return { ok: false, error: { code: "passkey_unavailable", message: "Passkeys cannot be used here." } };
@@ -401,7 +402,7 @@ function createAuthClient(options = {}) {
401
402
  },
402
403
  addPasskey(f = {}) {
403
404
  if (!canUsePasskeys()) return Promise.resolve({ ok: false, error: { code: "passkey_unavailable", message: "This browser cannot make passkeys." } });
404
- return ceremony("/me/passkeys/add/begin", "/me/passkeys/add/finish", { password: f.password ?? "" }, makePasskey, { name: f.name ?? "" });
405
+ return ceremony("/me/passkeys/add/begin", "/me/passkeys/add/finish", { password: f.password ?? "", ...f.kind ? { kind: f.kind } : {} }, makePasskey, { name: f.name ?? "" });
405
406
  },
406
407
  removePasskey: (id) => post("/me/passkeys/remove", { id }, null)
407
408
  },
@@ -542,6 +543,9 @@ var TEXTS = {
542
543
  passkeyName: "A name for this device (optional)",
543
544
  addPasskey: "Add a passkey on this device",
544
545
  removePasskey: "Remove",
546
+ addPasskeyDevice: "Add this device (fingerprint or face)",
547
+ addSecurityKey: "Add a security key",
548
+ passkeyKinds: { security_key: "Security key", synced: "Synced across your devices", device: "On this device only" },
545
549
  passkeyAdded: "The passkey was added. Next time, sign in with it.",
546
550
  passkeyUnnamed: "Passkey",
547
551
  sessions: "Where you are signed in",
@@ -654,6 +658,9 @@ var TEXTS = {
654
658
  passkeyName: "Un nombre para este dispositivo (opcional)",
655
659
  addPasskey: "Agregar una llave en este dispositivo",
656
660
  removePasskey: "Quitar",
661
+ addPasskeyDevice: "Agregar este dispositivo (huella o rostro)",
662
+ addSecurityKey: "Agregar una llave f\xEDsica",
663
+ passkeyKinds: { security_key: "Llave f\xEDsica", synced: "Sincronizada entre tus dispositivos", device: "Solo en un dispositivo" },
657
664
  passkeyAdded: "La llave de acceso qued\xF3 agregada. La pr\xF3xima vez, entra con ella.",
658
665
  passkeyUnnamed: "Llave de acceso",
659
666
  sessions: "D\xF3nde tienes la sesi\xF3n abierta",
@@ -939,7 +946,7 @@ function SignIn(props) {
939
946
  autofill.current?.abort();
940
947
  f.setBusy(true);
941
948
  f.setError(null);
942
- const r = await auth.signIn.passkey({ returnTo: props.returnTo, locale: props.locale });
949
+ const r = await auth.signIn.passkey({ returnTo: props.returnTo, locale: props.locale, email });
943
950
  if (r.ok && r.status === "redirected") return;
944
951
  f.setBusy(false);
945
952
  if (!r.ok) setOffer((n) => n + 1);
@@ -1229,9 +1236,9 @@ function PasskeysPart({ props, account, accountUrl, when }) {
1229
1236
  /* @__PURE__ */ jsx("a", { className: f.cx("link"), href: accountUrl, children: f.t.managePasskeys })
1230
1237
  ] });
1231
1238
  }
1232
- const add = async (e) => {
1233
- e.preventDefault();
1234
- const r = await run(() => auth.account.addPasskey({ name, password }));
1239
+ const add = async (e, kind = "device") => {
1240
+ e?.preventDefault();
1241
+ const r = await run(() => auth.account.addPasskey({ name, password, kind }));
1235
1242
  if (!r.ok) {
1236
1243
  if (r.error.code === "cancelled") f.setError(null);
1237
1244
  return;
@@ -1251,6 +1258,7 @@ function PasskeysPart({ props, account, accountUrl, when }) {
1251
1258
  general && /* @__PURE__ */ jsx("p", { role: "alert", className: f.cx("error"), children: f.say(general) }),
1252
1259
  list.length === 0 ? /* @__PURE__ */ jsx("p", { className: f.cx("notice"), children: f.t.noPasskeys }) : /* @__PURE__ */ jsx("ul", { className: f.cx("sessions"), children: list.map((p) => /* @__PURE__ */ jsxs("li", { className: f.cx("session"), children: [
1253
1260
  p.name || f.t.passkeyUnnamed,
1261
+ p.kind !== "unknown" ? ` \xB7 ${f.t.passkeyKinds[p.kind]}` : "",
1254
1262
  " \xB7 ",
1255
1263
  when(p.createdAt),
1256
1264
  " ",
@@ -1258,7 +1266,8 @@ function PasskeysPart({ props, account, accountUrl, when }) {
1258
1266
  ] }, p.id)) }),
1259
1267
  /* @__PURE__ */ jsx(Field, { f, name: "name", type: "text", label: f.t.passkeyName, value: name, autoComplete: "off", onChange: setName }),
1260
1268
  account.hasPassword && /* @__PURE__ */ jsx(Field, { f, name: "password", type: "password", label: f.t.currentPassword, value: password, autoComplete: "current-password", required: true, onChange: setPassword }),
1261
- /* @__PURE__ */ jsx(f.Button, { type: "submit", disabled: f.busy, className: f.cx("button"), children: f.t.addPasskey }),
1269
+ /* @__PURE__ */ jsx(f.Button, { type: "submit", disabled: f.busy, className: f.cx("button"), children: f.t.addPasskeyDevice }),
1270
+ /* @__PURE__ */ jsx(f.Button, { type: "button", disabled: f.busy, className: f.cx("providerButton"), onClick: () => void add(null, "security_key"), children: f.t.addSecurityKey }),
1262
1271
  done && /* @__PURE__ */ jsx("p", { role: "status", className: f.cx("notice"), children: done })
1263
1272
  ] });
1264
1273
  }