cauthy-auth 0.24.2 → 0.25.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
@@ -173,6 +173,13 @@ function checkName(value) {
173
173
  if (typeof value !== "string" || value.trim().length > MAX_NAME) return { field: "name", code: "too_long", message: `Use at most ${MAX_NAME} characters.` };
174
174
  return null;
175
175
  }
176
+ var MAX_ORGANIZATION = 120;
177
+ function checkOrganization(value, required = false) {
178
+ const v = typeof value === "string" ? value.trim() : "";
179
+ if (v === "") return required ? { field: "organization", code: "required", message: "Enter your company's name." } : null;
180
+ if (v.length > MAX_ORGANIZATION) return { field: "organization", code: "too_long", message: `Use at most ${MAX_ORGANIZATION} characters.` };
181
+ return null;
182
+ }
176
183
  function checkCode(value) {
177
184
  const v = typeof value === "string" ? value.trim() : "";
178
185
  if (v === "") return { field: "code", code: "required", message: "Enter the code." };
@@ -395,7 +402,12 @@ function createAuthClient(options = {}) {
395
402
  }
396
403
  },
397
404
  signUp: {
398
- email: (f) => post("/sign-up/email", { email: f.email, password: f.password, name: f.name }, firstProblem(checkName(f.name), checkEmail(f.email), checkNewPassword(f.password)), f.captchaToken)
405
+ email: (f) => post(
406
+ "/sign-up/email",
407
+ { email: f.email, password: f.password, name: f.name, organization: f.organization },
408
+ firstProblem(checkName(f.name), checkEmail(f.email), checkNewPassword(f.password), checkOrganization(f.organization)),
409
+ f.captchaToken
410
+ )
399
411
  },
400
412
  forgotPassword: (f) => post("/forgot-password", { email: f.email }, checkEmail(f.email), f.captchaToken),
401
413
  resetPassword: (f) => post("/reset-password", { token: f.token, password: f.password }, checkNewPassword(f.password)),
@@ -555,6 +567,7 @@ var TEXTS = {
555
567
  email: "Email",
556
568
  password: "Password",
557
569
  name: "Name",
570
+ company: "Your company's name",
558
571
  code: "Code",
559
572
  signIn: "Sign in",
560
573
  signUp: "Create account",
@@ -583,7 +596,7 @@ var TEXTS = {
583
596
  removePhone: "Remove phone",
584
597
  bySms: "SMS",
585
598
  byWhatsapp: "WhatsApp",
586
- checkEmail: "Almost there: open the link we sent to confirm your address, then sign in.",
599
+ checkEmail: "Almost there: open the link we sent to confirm your address \u2014 it signs you in.",
587
600
  backToSignIn: "Back to sign in",
588
601
  emailMeALink: "Email me a sign-in link",
589
602
  usePasskey: "Sign in with a passkey",
@@ -704,6 +717,7 @@ var TEXTS = {
704
717
  email: "Correo",
705
718
  password: "Contrase\xF1a",
706
719
  name: "Nombre",
720
+ company: "Nombre de tu empresa",
707
721
  code: "C\xF3digo",
708
722
  signIn: "Entrar",
709
723
  signUp: "Crear cuenta",
@@ -732,7 +746,7 @@ var TEXTS = {
732
746
  removePhone: "Quitar tel\xE9fono",
733
747
  bySms: "SMS",
734
748
  byWhatsapp: "WhatsApp",
735
- checkEmail: "Ya casi: abre el enlace que te enviamos para confirmar tu correo y luego entra.",
749
+ checkEmail: "Casi listo: abre el enlace que te enviamos para confirmar tu correo; te deja adentro.",
736
750
  backToSignIn: "Volver a entrar",
737
751
  emailMeALink: "Env\xEDame un enlace para entrar",
738
752
  usePasskey: "Entrar con una llave de acceso",
@@ -1243,15 +1257,17 @@ function SignUp(props) {
1243
1257
  const auth = useAuth();
1244
1258
  const f = useForm(props);
1245
1259
  const [name, setName] = useState("");
1260
+ const [organization, setOrganization] = useState("");
1246
1261
  const [email, setEmail] = useState("");
1247
1262
  const [password, setPassword] = useState("");
1248
1263
  const [sent, setSent] = useState(false);
1249
- const challenge = useChallenge(useMethods(auth)?.captchaSiteKey, props.locale);
1264
+ const methods = useMethods(auth);
1265
+ const challenge = useChallenge(methods?.captchaSiteKey, props.locale);
1250
1266
  const submit = async (e) => {
1251
1267
  e.preventDefault();
1252
1268
  f.setBusy(true);
1253
1269
  f.setError(null);
1254
- const r = auth.session?.user.isAnonymous === true ? await auth.account.upgrade({ name, email, password }) : await auth.signUp.email({ name, email, password, captchaToken: challenge.token });
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 });
1255
1271
  f.setBusy(false);
1256
1272
  challenge.renew();
1257
1273
  if (!r.ok) return f.setError(r.error);
@@ -1267,6 +1283,7 @@ function SignUp(props) {
1267
1283
  }
1268
1284
  return /* @__PURE__ */ jsxs("form", { className: f.cx("form"), ...f.root, onSubmit: submit, noValidate: true, children: [
1269
1285
  general && /* @__PURE__ */ jsx("p", { role: "alert", className: f.cx("error"), children: f.say(general) }),
1286
+ methods?.organization?.ask && /* @__PURE__ */ jsx(Field, { f, name: "organization", type: "text", label: f.t.company, value: organization, autoComplete: "organization", required: methods.organization.required, onChange: setOrganization }),
1270
1287
  /* @__PURE__ */ jsx(Field, { f, name: "name", type: "text", label: f.t.name, value: name, autoComplete: "name", onChange: setName }),
1271
1288
  /* @__PURE__ */ jsx(Field, { f, name: "email", type: "email", label: f.t.email, value: email, autoComplete: "username", required: true, onChange: setEmail }),
1272
1289
  /* @__PURE__ */ jsx(Field, { f, name: "password", type: "password", label: f.t.password, value: password, autoComplete: "new-password", required: true, onChange: setPassword }),
@@ -1359,6 +1376,7 @@ function VerifyEmail(props) {
1359
1376
  return setState("failed");
1360
1377
  }
1361
1378
  void auth.verifyEmail({ token }).then((r) => {
1379
+ if (r.ok && r.status === "signed_in") return f.done();
1362
1380
  if (r.ok) return setState("confirmed");
1363
1381
  f.setError(r.error);
1364
1382
  setState("failed");