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/react.mjs CHANGED
@@ -286,6 +286,7 @@ function createAuthClient(options = {}) {
286
286
  mfa: (f) => post("/sign-in/mfa", { code: f.code }, checkCode(f.code)),
287
287
  mfaMethods: () => post("/sign-in/mfa/methods", {}, null),
288
288
  mfaSendCode: () => post("/sign-in/mfa/send", {}, null),
289
+ mfaSendEmail: () => post("/sign-in/mfa/email", {}, null),
289
290
  mfaPush: () => post("/sign-in/mfa/push", {}, null),
290
291
  async mfaPushWait(o = {}) {
291
292
  const status = await new Promise((resolve) => {
@@ -582,6 +583,8 @@ var TEXTS = {
582
583
  codeHelp: "Enter the code from your authenticator app, or a recovery code.",
583
584
  verify: "Verify",
584
585
  codeHelpPhone: "We send a code to your phone. Ask for it, then type it here, or use a recovery code.",
586
+ codeHelpEmail: "We sent a code to {to}. Type it here.",
587
+ sendEmailAgain: "Send the code again",
585
588
  sendCodeSms: "Send a code by SMS to {to}",
586
589
  sendCodeWhatsapp: "Send a code by WhatsApp to {to}",
587
590
  codeSent: "We sent a code to {to}. Type it here.",
@@ -732,6 +735,8 @@ var TEXTS = {
732
735
  codeHelp: "Escribe el c\xF3digo de tu aplicaci\xF3n de autenticaci\xF3n, o un c\xF3digo de recuperaci\xF3n.",
733
736
  verify: "Verificar",
734
737
  codeHelpPhone: "Te enviamos un c\xF3digo a tu tel\xE9fono. P\xEDdelo y escr\xEDbelo aqu\xED, o usa un c\xF3digo de recuperaci\xF3n.",
738
+ codeHelpEmail: "Te enviamos un c\xF3digo a {to}. Escr\xEDbelo aqu\xED.",
739
+ sendEmailAgain: "Enviar el c\xF3digo de nuevo",
735
740
  sendCodeSms: "Enviar un c\xF3digo por SMS a {to}",
736
741
  sendCodeWhatsapp: "Enviar un c\xF3digo por WhatsApp a {to}",
737
742
  codeSent: "Te enviamos un c\xF3digo a {to}. Escr\xEDbelo aqu\xED.",
@@ -1050,9 +1055,17 @@ function SignIn(props) {
1050
1055
  useEffect(() => {
1051
1056
  if (step !== "code") return;
1052
1057
  void auth.signIn.mfaMethods().then((r) => {
1053
- if (r.ok) setPhoneWay({ totp: r.totp, phone: r.phone, push: r.push });
1058
+ if (r.ok) setPhoneWay({ totp: r.totp, phone: r.phone, push: r.push, email: r.email });
1054
1059
  });
1055
1060
  }, [step]);
1061
+ const sendEmail = async () => {
1062
+ f.setBusy(true);
1063
+ f.setError(null);
1064
+ const r = await auth.signIn.mfaSendEmail();
1065
+ f.setBusy(false);
1066
+ if (!r.ok) return f.setError(r.error);
1067
+ setPhoneSent(r.sentTo);
1068
+ };
1056
1069
  const [pushNumber, setPushNumber] = useState(0);
1057
1070
  const pushWait = useRef(null);
1058
1071
  useEffect(() => () => pushWait.current?.abort(), []);
@@ -1181,8 +1194,9 @@ function SignIn(props) {
1181
1194
  if (step === "code") {
1182
1195
  const to = phoneWay?.phone?.number ?? "";
1183
1196
  return /* @__PURE__ */ jsxs("form", { className: f.cx("form"), ...f.root, onSubmit: submit, noValidate: true, children: [
1184
- /* @__PURE__ */ jsx("p", { className: f.cx("notice"), children: phoneSent ? f.t.codeSent.replace("{to}", phoneSent) : phoneWay?.phone && !phoneWay.totp ? f.t.codeHelpPhone : f.t.codeHelp }),
1197
+ /* @__PURE__ */ jsx("p", { className: f.cx("notice"), children: phoneSent ? f.t.codeSent.replace("{to}", phoneSent) : phoneWay?.email ? f.t.codeHelpEmail.replace("{to}", phoneWay.email.to) : phoneWay?.phone && !phoneWay.totp ? f.t.codeHelpPhone : f.t.codeHelp }),
1185
1198
  general && /* @__PURE__ */ jsx("p", { role: "alert", className: f.cx("error"), children: f.say(general) }),
1199
+ phoneWay?.email && /* @__PURE__ */ jsx(f.Button, { type: "button", disabled: f.busy, className: f.cx("providerButton"), onClick: () => void sendEmail(), children: f.t.sendEmailAgain }),
1186
1200
  pushNumber > 0 ? /* @__PURE__ */ jsxs("div", { className: f.cx("notice"), role: "status", "aria-live": "polite", children: [
1187
1201
  /* @__PURE__ */ jsx("p", { children: f.t.pushPick.replace("{n}", String(pushNumber)) }),
1188
1202
  /* @__PURE__ */ jsx("p", { style: { fontSize: 48, fontWeight: 700, margin: "4px 0", textAlign: "center" }, children: pushNumber }),