cauthy-auth 0.26.0 → 0.27.1

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
@@ -145,8 +145,8 @@ function fromWire(wire) {
145
145
  }
146
146
 
147
147
  // src/validate.ts
148
- var MIN_PASSWORD = 8;
149
- var MAX_PASSWORD = 256;
148
+ var MIN_PASSWORD = 12;
149
+ var MAX_PASSWORD = 128;
150
150
  var MAX_NAME = 120;
151
151
  var EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
152
152
  function checkEmail(value) {
@@ -405,7 +405,7 @@ function createAuthClient(options = {}) {
405
405
  signUp: {
406
406
  email: (f) => post(
407
407
  "/sign-up/email",
408
- { 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 },
409
409
  firstProblem(checkName(f.name), checkEmail(f.email), checkNewPassword(f.password), checkOrganization(f.organization)),
410
410
  f.captchaToken
411
411
  )
@@ -438,6 +438,12 @@ function createAuthClient(options = {}) {
438
438
  return body && typeof body.account === "object" ? body.account : null;
439
439
  },
440
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),
441
447
  changePassword: (f) => {
442
448
  const bad = checkNewPassword(f.newPassword);
443
449
  return post("/me/password", { password: f.password, newPassword: f.newPassword }, bad ? { ...bad, field: "newPassword" } : null);
@@ -578,6 +584,10 @@ var TEXTS = {
578
584
  noAccount: "No account yet?",
579
585
  createAccount: "Create one",
580
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",
581
591
  sendLink: "Send the link",
582
592
  linkSent: "If that address has an account, a link to choose a new password is on its way.",
583
593
  codeHelp: "Enter the code from your authenticator app, or a recovery code.",
@@ -680,7 +690,7 @@ var TEXTS = {
680
690
  user_not_active: "That account is disabled.",
681
691
  required: "This is required.",
682
692
  invalid_email: "That does not look like an email address.",
683
- too_short: "Use at least 8 characters.",
693
+ too_short: `Use at least ${MIN_PASSWORD} characters.`,
684
694
  invalid_credentials: "The address or the password is not right.",
685
695
  unavailable: "Sign-in is unavailable right now. Try again in a moment.",
686
696
  state_mismatch: "That sign-in could not be completed. Try again.",
@@ -730,6 +740,10 @@ var TEXTS = {
730
740
  noAccount: "\xBFNo tienes cuenta?",
731
741
  createAccount: "Crear una",
732
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",
733
747
  sendLink: "Enviar el enlace",
734
748
  linkSent: "Si ese correo tiene una cuenta, ya va en camino un enlace para elegir una contrase\xF1a nueva.",
735
749
  codeHelp: "Escribe el c\xF3digo de tu aplicaci\xF3n de autenticaci\xF3n, o un c\xF3digo de recuperaci\xF3n.",
@@ -832,7 +846,7 @@ var TEXTS = {
832
846
  user_not_active: "Esa cuenta est\xE1 desactivada.",
833
847
  required: "Este dato es obligatorio.",
834
848
  invalid_email: "Eso no parece un correo.",
835
- too_short: "Usa al menos 8 caracteres.",
849
+ too_short: `Usa al menos ${MIN_PASSWORD} caracteres.`,
836
850
  invalid_credentials: "El correo o la contrase\xF1a no son correctos.",
837
851
  unavailable: "No se puede entrar en este momento. Intenta de nuevo en un momento.",
838
852
  state_mismatch: "No se pudo completar el ingreso. Intenta de nuevo.",
@@ -1277,11 +1291,21 @@ function SignUp(props) {
1277
1291
  const [sent, setSent] = useState(false);
1278
1292
  const methods = useMethods(auth);
1279
1293
  const challenge = useChallenge(methods?.captchaSiteKey, props.locale);
1294
+ const [acceptLegal, setAcceptLegal] = useState(false);
1295
+ const [consents, setConsents] = useState({});
1296
+ const legal = methods?.legal;
1280
1297
  const submit = async (e) => {
1281
1298
  e.preventDefault();
1282
1299
  f.setBusy(true);
1283
1300
  f.setError(null);
1284
- 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
+ });
1285
1309
  f.setBusy(false);
1286
1310
  challenge.renew();
1287
1311
  if (!r.ok) return f.setError(r.error);
@@ -1301,6 +1325,25 @@ function SignUp(props) {
1301
1325
  /* @__PURE__ */ jsx(Field, { f, name: "name", type: "text", label: f.t.name, value: name, autoComplete: "name", onChange: setName }),
1302
1326
  /* @__PURE__ */ jsx(Field, { f, name: "email", type: "email", label: f.t.email, value: email, autoComplete: "username", required: true, onChange: setEmail }),
1303
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)),
1304
1347
  challenge.node,
1305
1348
  /* @__PURE__ */ jsx(f.Button, { type: "submit", disabled: f.busy, className: f.cx("button"), children: f.t.signUp }),
1306
1349
  props.links?.signIn && /* @__PURE__ */ jsxs("p", { className: f.cx("footer"), children: [