cauthy-auth 0.25.0 → 0.27.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) => {
@@ -404,7 +405,7 @@ function createAuthClient(options = {}) {
404
405
  signUp: {
405
406
  email: (f) => post(
406
407
  "/sign-up/email",
407
- { email: f.email, password: f.password, name: f.name, organization: f.organization },
408
+ { email: f.email, password: f.password, name: f.name, organization: f.organization, acceptLegal: f.acceptLegal, consents: f.consents },
408
409
  firstProblem(checkName(f.name), checkEmail(f.email), checkNewPassword(f.password), checkOrganization(f.organization)),
409
410
  f.captchaToken
410
411
  )
@@ -437,6 +438,12 @@ function createAuthClient(options = {}) {
437
438
  return body && typeof body.account === "object" ? body.account : null;
438
439
  },
439
440
  update: (f) => post("/me", { name: f.name }, checkName(f.name)),
441
+ async legal() {
442
+ const body = await read("/me/legal");
443
+ if (!body) return { ok: false, error: { code: "not_signed_in", message: "Nobody is signed in." } };
444
+ return { ok: true, status: "ok", pending: Array.isArray(body.pending) ? body.pending : [] };
445
+ },
446
+ acceptLegal: (f = {}) => post("/me/legal/accept", { kinds: f.kinds ?? [] }, null),
440
447
  changePassword: (f) => {
441
448
  const bad = checkNewPassword(f.newPassword);
442
449
  return post("/me/password", { password: f.password, newPassword: f.newPassword }, bad ? { ...bad, field: "newPassword" } : null);
@@ -577,11 +584,17 @@ var TEXTS = {
577
584
  noAccount: "No account yet?",
578
585
  createAccount: "Create one",
579
586
  haveAccount: "Already have an account?",
587
+ iAccept: "I have read and accept",
588
+ and: "and",
589
+ termsOfService: "the Terms of Service",
590
+ privacyPolicy: "the Privacy Policy",
580
591
  sendLink: "Send the link",
581
592
  linkSent: "If that address has an account, a link to choose a new password is on its way.",
582
593
  codeHelp: "Enter the code from your authenticator app, or a recovery code.",
583
594
  verify: "Verify",
584
595
  codeHelpPhone: "We send a code to your phone. Ask for it, then type it here, or use a recovery code.",
596
+ codeHelpEmail: "We sent a code to {to}. Type it here.",
597
+ sendEmailAgain: "Send the code again",
585
598
  sendCodeSms: "Send a code by SMS to {to}",
586
599
  sendCodeWhatsapp: "Send a code by WhatsApp to {to}",
587
600
  codeSent: "We sent a code to {to}. Type it here.",
@@ -727,11 +740,17 @@ var TEXTS = {
727
740
  noAccount: "\xBFNo tienes cuenta?",
728
741
  createAccount: "Crear una",
729
742
  haveAccount: "\xBFYa tienes cuenta?",
743
+ iAccept: "He le\xEDdo y acepto",
744
+ and: "y",
745
+ termsOfService: "los T\xE9rminos del servicio",
746
+ privacyPolicy: "la Pol\xEDtica de privacidad",
730
747
  sendLink: "Enviar el enlace",
731
748
  linkSent: "Si ese correo tiene una cuenta, ya va en camino un enlace para elegir una contrase\xF1a nueva.",
732
749
  codeHelp: "Escribe el c\xF3digo de tu aplicaci\xF3n de autenticaci\xF3n, o un c\xF3digo de recuperaci\xF3n.",
733
750
  verify: "Verificar",
734
751
  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.",
752
+ codeHelpEmail: "Te enviamos un c\xF3digo a {to}. Escr\xEDbelo aqu\xED.",
753
+ sendEmailAgain: "Enviar el c\xF3digo de nuevo",
735
754
  sendCodeSms: "Enviar un c\xF3digo por SMS a {to}",
736
755
  sendCodeWhatsapp: "Enviar un c\xF3digo por WhatsApp a {to}",
737
756
  codeSent: "Te enviamos un c\xF3digo a {to}. Escr\xEDbelo aqu\xED.",
@@ -1050,9 +1069,17 @@ function SignIn(props) {
1050
1069
  useEffect(() => {
1051
1070
  if (step !== "code") return;
1052
1071
  void auth.signIn.mfaMethods().then((r) => {
1053
- if (r.ok) setPhoneWay({ totp: r.totp, phone: r.phone, push: r.push });
1072
+ if (r.ok) setPhoneWay({ totp: r.totp, phone: r.phone, push: r.push, email: r.email });
1054
1073
  });
1055
1074
  }, [step]);
1075
+ const sendEmail = async () => {
1076
+ f.setBusy(true);
1077
+ f.setError(null);
1078
+ const r = await auth.signIn.mfaSendEmail();
1079
+ f.setBusy(false);
1080
+ if (!r.ok) return f.setError(r.error);
1081
+ setPhoneSent(r.sentTo);
1082
+ };
1056
1083
  const [pushNumber, setPushNumber] = useState(0);
1057
1084
  const pushWait = useRef(null);
1058
1085
  useEffect(() => () => pushWait.current?.abort(), []);
@@ -1181,8 +1208,9 @@ function SignIn(props) {
1181
1208
  if (step === "code") {
1182
1209
  const to = phoneWay?.phone?.number ?? "";
1183
1210
  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 }),
1211
+ /* @__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
1212
  general && /* @__PURE__ */ jsx("p", { role: "alert", className: f.cx("error"), children: f.say(general) }),
1213
+ phoneWay?.email && /* @__PURE__ */ jsx(f.Button, { type: "button", disabled: f.busy, className: f.cx("providerButton"), onClick: () => void sendEmail(), children: f.t.sendEmailAgain }),
1186
1214
  pushNumber > 0 ? /* @__PURE__ */ jsxs("div", { className: f.cx("notice"), role: "status", "aria-live": "polite", children: [
1187
1215
  /* @__PURE__ */ jsx("p", { children: f.t.pushPick.replace("{n}", String(pushNumber)) }),
1188
1216
  /* @__PURE__ */ jsx("p", { style: { fontSize: 48, fontWeight: 700, margin: "4px 0", textAlign: "center" }, children: pushNumber }),
@@ -1263,11 +1291,21 @@ function SignUp(props) {
1263
1291
  const [sent, setSent] = useState(false);
1264
1292
  const methods = useMethods(auth);
1265
1293
  const challenge = useChallenge(methods?.captchaSiteKey, props.locale);
1294
+ const [acceptLegal, setAcceptLegal] = useState(false);
1295
+ const [consents, setConsents] = useState({});
1296
+ const legal = methods?.legal;
1266
1297
  const submit = async (e) => {
1267
1298
  e.preventDefault();
1268
1299
  f.setBusy(true);
1269
1300
  f.setError(null);
1270
- const r = auth.session?.user.isAnonymous === true ? await auth.account.upgrade({ name, email, password }) : await auth.signUp.email({ name, email, password, ...methods?.organization?.ask ? { organization } : {}, captchaToken: challenge.token });
1301
+ const r = auth.session?.user.isAnonymous === true ? await auth.account.upgrade({ name, email, password }) : await auth.signUp.email({
1302
+ name,
1303
+ email,
1304
+ password,
1305
+ ...methods?.organization?.ask ? { organization } : {},
1306
+ ...legal ? { acceptLegal, consents } : {},
1307
+ captchaToken: challenge.token
1308
+ });
1271
1309
  f.setBusy(false);
1272
1310
  challenge.renew();
1273
1311
  if (!r.ok) return f.setError(r.error);
@@ -1287,6 +1325,25 @@ function SignUp(props) {
1287
1325
  /* @__PURE__ */ jsx(Field, { f, name: "name", type: "text", label: f.t.name, value: name, autoComplete: "name", onChange: setName }),
1288
1326
  /* @__PURE__ */ jsx(Field, { f, name: "email", type: "email", label: f.t.email, value: email, autoComplete: "username", required: true, onChange: setEmail }),
1289
1327
  /* @__PURE__ */ jsx(Field, { f, name: "password", type: "password", label: f.t.password, value: password, autoComplete: "new-password", required: true, onChange: setPassword }),
1328
+ legal && legal.documents.length > 0 && /* @__PURE__ */ jsxs("label", { className: f.cx("check"), children: [
1329
+ /* @__PURE__ */ jsx("input", { type: "checkbox", name: "acceptLegal", checked: acceptLegal, required: true, onChange: (e) => setAcceptLegal(e.target.checked) }),
1330
+ /* @__PURE__ */ jsxs("span", { children: [
1331
+ f.t.iAccept,
1332
+ " ",
1333
+ legal.documents.map((d, i) => /* @__PURE__ */ jsxs("span", { children: [
1334
+ i > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
1335
+ f.t.and,
1336
+ " "
1337
+ ] }),
1338
+ /* @__PURE__ */ jsx("a", { className: f.cx("link"), href: d.url, target: "_blank", rel: "noopener", children: d.kind === "terms" ? f.t.termsOfService : f.t.privacyPolicy }),
1339
+ " "
1340
+ ] }, d.kind))
1341
+ ] })
1342
+ ] }),
1343
+ legal?.consentPurposes.map((p) => /* @__PURE__ */ jsxs("label", { className: f.cx("check"), children: [
1344
+ /* @__PURE__ */ jsx("input", { type: "checkbox", name: `consent_${p.key}`, checked: consents[p.key] === true, required: p.required, onChange: (e) => setConsents({ ...consents, [p.key]: e.target.checked }) }),
1345
+ /* @__PURE__ */ jsx("span", { children: p.label })
1346
+ ] }, p.key)),
1290
1347
  challenge.node,
1291
1348
  /* @__PURE__ */ jsx(f.Button, { type: "submit", disabled: f.busy, className: f.cx("button"), children: f.t.signUp }),
1292
1349
  props.links?.signIn && /* @__PURE__ */ jsxs("p", { className: f.cx("footer"), children: [