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.d.mts CHANGED
@@ -597,21 +597,34 @@ interface AuthClient {
597
597
  }): Promise<AuthResult<'signed_in', {
598
598
  session: PublicSession;
599
599
  }>>;
600
- /** With address and password. `mfa_required`: ask for the code and call `signIn.mfa`. */
600
+ /**
601
+ * With address and password. `mfa_required`: ask for the code and call
602
+ * `signIn.mfa`. `method: 'email'` says the code was just mailed to the
603
+ * account's address (it has no factor of its own and the workspace, or
604
+ * the sign-in's risk, asked a second step): say so, and offer
605
+ * `mfaSendEmail` for another.
606
+ */
601
607
  email(form: {
602
608
  email: string;
603
609
  password: string;
604
610
  captchaToken?: string;
605
611
  }): Promise<AuthResult<'signed_in', {
606
612
  session: PublicSession;
607
- }> | AuthResult<'mfa_required'>>;
608
- /** The second step: the code of the authenticator app, or a recovery code. */
613
+ }> | AuthResult<'mfa_required', {
614
+ method?: 'email';
615
+ }>>;
616
+ /** The second step: the code of the authenticator app, the phone, the email, or a recovery code. */
609
617
  mfa(form: {
610
618
  code: string;
611
619
  }): Promise<AuthResult<'signed_in', {
612
620
  session: PublicSession;
613
621
  }>>;
614
- /** While the second step is asked for: whether the account has an authenticator app, the phone (masked) a code can be sent to, and phones that approve sign-ins. */
622
+ /**
623
+ * While the second step is asked for: whether the account has an
624
+ * authenticator app, the phone (masked) a code can be sent to, phones
625
+ * that approve sign-ins, and the address (masked) a code went to when
626
+ * the step is by email.
627
+ */
615
628
  mfaMethods(): Promise<AuthResult<'ok', {
616
629
  totp: boolean;
617
630
  phone: {
@@ -621,6 +634,13 @@ interface AuthClient {
621
634
  push: {
622
635
  devices: number;
623
636
  } | null;
637
+ email: {
638
+ to: string;
639
+ } | null;
640
+ }>>;
641
+ /** Mails the sign-in's code again, when its second step is by email; `mfa` takes it. A few per sign-in. */
642
+ mfaSendEmail(): Promise<AuthResult<'sent', {
643
+ sentTo: string;
624
644
  }>>;
625
645
  /**
626
646
  * Sends a push to the account's phones (the application's app, with
@@ -843,6 +863,9 @@ interface AuthTexts {
843
863
  codeHelp: string;
844
864
  /** The second step when it is a phone only. */
845
865
  codeHelpPhone: string;
866
+ /** The second step by email (the account has no factor): "{to}" is the address, masked. */
867
+ codeHelpEmail: string;
868
+ sendEmailAgain: string;
846
869
  /** "{to}" is the phone, masked. */
847
870
  sendCodeSms: string;
848
871
  sendCodeWhatsapp: string;
package/dist/react.d.ts CHANGED
@@ -597,21 +597,34 @@ interface AuthClient {
597
597
  }): Promise<AuthResult<'signed_in', {
598
598
  session: PublicSession;
599
599
  }>>;
600
- /** With address and password. `mfa_required`: ask for the code and call `signIn.mfa`. */
600
+ /**
601
+ * With address and password. `mfa_required`: ask for the code and call
602
+ * `signIn.mfa`. `method: 'email'` says the code was just mailed to the
603
+ * account's address (it has no factor of its own and the workspace, or
604
+ * the sign-in's risk, asked a second step): say so, and offer
605
+ * `mfaSendEmail` for another.
606
+ */
601
607
  email(form: {
602
608
  email: string;
603
609
  password: string;
604
610
  captchaToken?: string;
605
611
  }): Promise<AuthResult<'signed_in', {
606
612
  session: PublicSession;
607
- }> | AuthResult<'mfa_required'>>;
608
- /** The second step: the code of the authenticator app, or a recovery code. */
613
+ }> | AuthResult<'mfa_required', {
614
+ method?: 'email';
615
+ }>>;
616
+ /** The second step: the code of the authenticator app, the phone, the email, or a recovery code. */
609
617
  mfa(form: {
610
618
  code: string;
611
619
  }): Promise<AuthResult<'signed_in', {
612
620
  session: PublicSession;
613
621
  }>>;
614
- /** While the second step is asked for: whether the account has an authenticator app, the phone (masked) a code can be sent to, and phones that approve sign-ins. */
622
+ /**
623
+ * While the second step is asked for: whether the account has an
624
+ * authenticator app, the phone (masked) a code can be sent to, phones
625
+ * that approve sign-ins, and the address (masked) a code went to when
626
+ * the step is by email.
627
+ */
615
628
  mfaMethods(): Promise<AuthResult<'ok', {
616
629
  totp: boolean;
617
630
  phone: {
@@ -621,6 +634,13 @@ interface AuthClient {
621
634
  push: {
622
635
  devices: number;
623
636
  } | null;
637
+ email: {
638
+ to: string;
639
+ } | null;
640
+ }>>;
641
+ /** Mails the sign-in's code again, when its second step is by email; `mfa` takes it. A few per sign-in. */
642
+ mfaSendEmail(): Promise<AuthResult<'sent', {
643
+ sentTo: string;
624
644
  }>>;
625
645
  /**
626
646
  * Sends a push to the account's phones (the application's app, with
@@ -843,6 +863,9 @@ interface AuthTexts {
843
863
  codeHelp: string;
844
864
  /** The second step when it is a phone only. */
845
865
  codeHelpPhone: string;
866
+ /** The second step by email (the account has no factor): "{to}" is the address, masked. */
867
+ codeHelpEmail: string;
868
+ sendEmailAgain: string;
846
869
  /** "{to}" is the phone, masked. */
847
870
  sendCodeSms: string;
848
871
  sendCodeWhatsapp: string;
package/dist/react.js CHANGED
@@ -324,6 +324,7 @@ function createAuthClient(options = {}) {
324
324
  mfa: (f) => post("/sign-in/mfa", { code: f.code }, checkCode(f.code)),
325
325
  mfaMethods: () => post("/sign-in/mfa/methods", {}, null),
326
326
  mfaSendCode: () => post("/sign-in/mfa/send", {}, null),
327
+ mfaSendEmail: () => post("/sign-in/mfa/email", {}, null),
327
328
  mfaPush: () => post("/sign-in/mfa/push", {}, null),
328
329
  async mfaPushWait(o = {}) {
329
330
  const status = await new Promise((resolve) => {
@@ -620,6 +621,8 @@ var TEXTS = {
620
621
  codeHelp: "Enter the code from your authenticator app, or a recovery code.",
621
622
  verify: "Verify",
622
623
  codeHelpPhone: "We send a code to your phone. Ask for it, then type it here, or use a recovery code.",
624
+ codeHelpEmail: "We sent a code to {to}. Type it here.",
625
+ sendEmailAgain: "Send the code again",
623
626
  sendCodeSms: "Send a code by SMS to {to}",
624
627
  sendCodeWhatsapp: "Send a code by WhatsApp to {to}",
625
628
  codeSent: "We sent a code to {to}. Type it here.",
@@ -770,6 +773,8 @@ var TEXTS = {
770
773
  codeHelp: "Escribe el c\xF3digo de tu aplicaci\xF3n de autenticaci\xF3n, o un c\xF3digo de recuperaci\xF3n.",
771
774
  verify: "Verificar",
772
775
  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.",
776
+ codeHelpEmail: "Te enviamos un c\xF3digo a {to}. Escr\xEDbelo aqu\xED.",
777
+ sendEmailAgain: "Enviar el c\xF3digo de nuevo",
773
778
  sendCodeSms: "Enviar un c\xF3digo por SMS a {to}",
774
779
  sendCodeWhatsapp: "Enviar un c\xF3digo por WhatsApp a {to}",
775
780
  codeSent: "Te enviamos un c\xF3digo a {to}. Escr\xEDbelo aqu\xED.",
@@ -1088,9 +1093,17 @@ function SignIn(props) {
1088
1093
  (0, import_react.useEffect)(() => {
1089
1094
  if (step !== "code") return;
1090
1095
  void auth.signIn.mfaMethods().then((r) => {
1091
- if (r.ok) setPhoneWay({ totp: r.totp, phone: r.phone, push: r.push });
1096
+ if (r.ok) setPhoneWay({ totp: r.totp, phone: r.phone, push: r.push, email: r.email });
1092
1097
  });
1093
1098
  }, [step]);
1099
+ const sendEmail = async () => {
1100
+ f.setBusy(true);
1101
+ f.setError(null);
1102
+ const r = await auth.signIn.mfaSendEmail();
1103
+ f.setBusy(false);
1104
+ if (!r.ok) return f.setError(r.error);
1105
+ setPhoneSent(r.sentTo);
1106
+ };
1094
1107
  const [pushNumber, setPushNumber] = (0, import_react.useState)(0);
1095
1108
  const pushWait = (0, import_react.useRef)(null);
1096
1109
  (0, import_react.useEffect)(() => () => pushWait.current?.abort(), []);
@@ -1219,8 +1232,9 @@ function SignIn(props) {
1219
1232
  if (step === "code") {
1220
1233
  const to = phoneWay?.phone?.number ?? "";
1221
1234
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("form", { className: f.cx("form"), ...f.root, onSubmit: submit, noValidate: true, children: [
1222
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: f.cx("notice"), children: phoneSent ? f.t.codeSent.replace("{to}", phoneSent) : phoneWay?.phone && !phoneWay.totp ? f.t.codeHelpPhone : f.t.codeHelp }),
1235
+ /* @__PURE__ */ (0, import_jsx_runtime.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 }),
1223
1236
  general && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { role: "alert", className: f.cx("error"), children: f.say(general) }),
1237
+ phoneWay?.email && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(f.Button, { type: "button", disabled: f.busy, className: f.cx("providerButton"), onClick: () => void sendEmail(), children: f.t.sendEmailAgain }),
1224
1238
  pushNumber > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: f.cx("notice"), role: "status", "aria-live": "polite", children: [
1225
1239
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: f.t.pushPick.replace("{n}", String(pushNumber)) }),
1226
1240
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { style: { fontSize: 48, fontWeight: 700, margin: "4px 0", textAlign: "center" }, children: pushNumber }),