cauthy-auth 0.24.3 → 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.d.mts CHANGED
@@ -210,7 +210,7 @@ interface PublicSession {
210
210
  expiresAt: string;
211
211
  }
212
212
 
213
- type AuthField = 'email' | 'password' | 'newPassword' | 'name' | 'code';
213
+ type AuthField = 'email' | 'password' | 'newPassword' | 'name' | 'code' | 'organization';
214
214
 
215
215
  /** Whether this browser can use a passkey at all. */
216
216
  declare function canUsePasskeys(): boolean;
@@ -245,6 +245,11 @@ interface AuthMethods {
245
245
  }[];
246
246
  /** Whether people may create an account themselves. */
247
247
  signUp: boolean;
248
+ /** Set when the application's system makes an organization per sign-up: the form asks the company's name. */
249
+ organization?: {
250
+ ask: boolean;
251
+ required: boolean;
252
+ };
248
253
  magicLink: boolean;
249
254
  /** Whether to offer a passkey. */
250
255
  passkey: boolean;
@@ -764,6 +769,7 @@ interface AuthClient {
764
769
  email: string;
765
770
  password: string;
766
771
  name?: string;
772
+ organization?: string;
767
773
  captchaToken?: string;
768
774
  }): Promise<AuthResult<'signed_in', {
769
775
  session: PublicSession;
@@ -782,9 +788,12 @@ interface AuthClient {
782
788
  password: string;
783
789
  }): Promise<AuthResult<'changed'>>;
784
790
  /** Confirms the address, with the token the mailed link opened the page with (`token`). */
791
+ /** Confirms the address a mailed link is for. The person is signed in from the link when their account asks no second step. */
785
792
  verifyEmail(form: {
786
793
  token: string;
787
- }): Promise<AuthResult<'verified'>>;
794
+ }): Promise<AuthResult<'verified'> | AuthResult<'signed_in', {
795
+ session: PublicSession;
796
+ }>>;
788
797
  signOut(): Promise<AuthResult<'signed_out'>>;
789
798
  /** The signed-in person's own account. */
790
799
  account: AccountClient;
@@ -826,6 +835,8 @@ interface AuthTexts {
826
835
  forgotPassword: string;
827
836
  noAccount: string;
828
837
  createAccount: string;
838
+ /** The label of the company's name, asked when the application's system makes an organization per sign-up. */
839
+ company: string;
829
840
  haveAccount: string;
830
841
  sendLink: string;
831
842
  linkSent: string;
package/dist/react.d.ts CHANGED
@@ -210,7 +210,7 @@ interface PublicSession {
210
210
  expiresAt: string;
211
211
  }
212
212
 
213
- type AuthField = 'email' | 'password' | 'newPassword' | 'name' | 'code';
213
+ type AuthField = 'email' | 'password' | 'newPassword' | 'name' | 'code' | 'organization';
214
214
 
215
215
  /** Whether this browser can use a passkey at all. */
216
216
  declare function canUsePasskeys(): boolean;
@@ -245,6 +245,11 @@ interface AuthMethods {
245
245
  }[];
246
246
  /** Whether people may create an account themselves. */
247
247
  signUp: boolean;
248
+ /** Set when the application's system makes an organization per sign-up: the form asks the company's name. */
249
+ organization?: {
250
+ ask: boolean;
251
+ required: boolean;
252
+ };
248
253
  magicLink: boolean;
249
254
  /** Whether to offer a passkey. */
250
255
  passkey: boolean;
@@ -764,6 +769,7 @@ interface AuthClient {
764
769
  email: string;
765
770
  password: string;
766
771
  name?: string;
772
+ organization?: string;
767
773
  captchaToken?: string;
768
774
  }): Promise<AuthResult<'signed_in', {
769
775
  session: PublicSession;
@@ -782,9 +788,12 @@ interface AuthClient {
782
788
  password: string;
783
789
  }): Promise<AuthResult<'changed'>>;
784
790
  /** Confirms the address, with the token the mailed link opened the page with (`token`). */
791
+ /** Confirms the address a mailed link is for. The person is signed in from the link when their account asks no second step. */
785
792
  verifyEmail(form: {
786
793
  token: string;
787
- }): Promise<AuthResult<'verified'>>;
794
+ }): Promise<AuthResult<'verified'> | AuthResult<'signed_in', {
795
+ session: PublicSession;
796
+ }>>;
788
797
  signOut(): Promise<AuthResult<'signed_out'>>;
789
798
  /** The signed-in person's own account. */
790
799
  account: AccountClient;
@@ -826,6 +835,8 @@ interface AuthTexts {
826
835
  forgotPassword: string;
827
836
  noAccount: string;
828
837
  createAccount: string;
838
+ /** The label of the company's name, asked when the application's system makes an organization per sign-up. */
839
+ company: string;
829
840
  haveAccount: string;
830
841
  sendLink: string;
831
842
  linkSent: string;
package/dist/react.js CHANGED
@@ -211,6 +211,13 @@ function checkName(value) {
211
211
  if (typeof value !== "string" || value.trim().length > MAX_NAME) return { field: "name", code: "too_long", message: `Use at most ${MAX_NAME} characters.` };
212
212
  return null;
213
213
  }
214
+ var MAX_ORGANIZATION = 120;
215
+ function checkOrganization(value, required = false) {
216
+ const v = typeof value === "string" ? value.trim() : "";
217
+ if (v === "") return required ? { field: "organization", code: "required", message: "Enter your company's name." } : null;
218
+ if (v.length > MAX_ORGANIZATION) return { field: "organization", code: "too_long", message: `Use at most ${MAX_ORGANIZATION} characters.` };
219
+ return null;
220
+ }
214
221
  function checkCode(value) {
215
222
  const v = typeof value === "string" ? value.trim() : "";
216
223
  if (v === "") return { field: "code", code: "required", message: "Enter the code." };
@@ -433,7 +440,12 @@ function createAuthClient(options = {}) {
433
440
  }
434
441
  },
435
442
  signUp: {
436
- 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)
443
+ email: (f) => post(
444
+ "/sign-up/email",
445
+ { email: f.email, password: f.password, name: f.name, organization: f.organization },
446
+ firstProblem(checkName(f.name), checkEmail(f.email), checkNewPassword(f.password), checkOrganization(f.organization)),
447
+ f.captchaToken
448
+ )
437
449
  },
438
450
  forgotPassword: (f) => post("/forgot-password", { email: f.email }, checkEmail(f.email), f.captchaToken),
439
451
  resetPassword: (f) => post("/reset-password", { token: f.token, password: f.password }, checkNewPassword(f.password)),
@@ -593,6 +605,7 @@ var TEXTS = {
593
605
  email: "Email",
594
606
  password: "Password",
595
607
  name: "Name",
608
+ company: "Your company's name",
596
609
  code: "Code",
597
610
  signIn: "Sign in",
598
611
  signUp: "Create account",
@@ -621,7 +634,7 @@ var TEXTS = {
621
634
  removePhone: "Remove phone",
622
635
  bySms: "SMS",
623
636
  byWhatsapp: "WhatsApp",
624
- checkEmail: "Almost there: open the link we sent to confirm your address, then sign in.",
637
+ checkEmail: "Almost there: open the link we sent to confirm your address \u2014 it signs you in.",
625
638
  backToSignIn: "Back to sign in",
626
639
  emailMeALink: "Email me a sign-in link",
627
640
  usePasskey: "Sign in with a passkey",
@@ -742,6 +755,7 @@ var TEXTS = {
742
755
  email: "Correo",
743
756
  password: "Contrase\xF1a",
744
757
  name: "Nombre",
758
+ company: "Nombre de tu empresa",
745
759
  code: "C\xF3digo",
746
760
  signIn: "Entrar",
747
761
  signUp: "Crear cuenta",
@@ -770,7 +784,7 @@ var TEXTS = {
770
784
  removePhone: "Quitar tel\xE9fono",
771
785
  bySms: "SMS",
772
786
  byWhatsapp: "WhatsApp",
773
- checkEmail: "Ya casi: abre el enlace que te enviamos para confirmar tu correo y luego entra.",
787
+ checkEmail: "Casi listo: abre el enlace que te enviamos para confirmar tu correo; te deja adentro.",
774
788
  backToSignIn: "Volver a entrar",
775
789
  emailMeALink: "Env\xEDame un enlace para entrar",
776
790
  usePasskey: "Entrar con una llave de acceso",
@@ -1281,15 +1295,17 @@ function SignUp(props) {
1281
1295
  const auth = useAuth();
1282
1296
  const f = useForm(props);
1283
1297
  const [name, setName] = (0, import_react.useState)("");
1298
+ const [organization, setOrganization] = (0, import_react.useState)("");
1284
1299
  const [email, setEmail] = (0, import_react.useState)("");
1285
1300
  const [password, setPassword] = (0, import_react.useState)("");
1286
1301
  const [sent, setSent] = (0, import_react.useState)(false);
1287
- const challenge = useChallenge(useMethods(auth)?.captchaSiteKey, props.locale);
1302
+ const methods = useMethods(auth);
1303
+ const challenge = useChallenge(methods?.captchaSiteKey, props.locale);
1288
1304
  const submit = async (e) => {
1289
1305
  e.preventDefault();
1290
1306
  f.setBusy(true);
1291
1307
  f.setError(null);
1292
- const r = auth.session?.user.isAnonymous === true ? await auth.account.upgrade({ name, email, password }) : await auth.signUp.email({ name, email, password, captchaToken: challenge.token });
1308
+ 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 });
1293
1309
  f.setBusy(false);
1294
1310
  challenge.renew();
1295
1311
  if (!r.ok) return f.setError(r.error);
@@ -1305,6 +1321,7 @@ function SignUp(props) {
1305
1321
  }
1306
1322
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("form", { className: f.cx("form"), ...f.root, onSubmit: submit, noValidate: true, children: [
1307
1323
  general && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { role: "alert", className: f.cx("error"), children: f.say(general) }),
1324
+ methods?.organization?.ask && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, { f, name: "organization", type: "text", label: f.t.company, value: organization, autoComplete: "organization", required: methods.organization.required, onChange: setOrganization }),
1308
1325
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, { f, name: "name", type: "text", label: f.t.name, value: name, autoComplete: "name", onChange: setName }),
1309
1326
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, { f, name: "email", type: "email", label: f.t.email, value: email, autoComplete: "username", required: true, onChange: setEmail }),
1310
1327
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, { f, name: "password", type: "password", label: f.t.password, value: password, autoComplete: "new-password", required: true, onChange: setPassword }),
@@ -1397,6 +1414,7 @@ function VerifyEmail(props) {
1397
1414
  return setState("failed");
1398
1415
  }
1399
1416
  void auth.verifyEmail({ token }).then((r) => {
1417
+ if (r.ok && r.status === "signed_in") return f.done();
1400
1418
  if (r.ok) return setState("confirmed");
1401
1419
  f.setError(r.error);
1402
1420
  setState("failed");