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/index.js CHANGED
@@ -681,6 +681,13 @@ function checkName(value) {
681
681
  if (typeof value !== "string" || value.trim().length > MAX_NAME) return { field: "name", code: "too_long", message: `Use at most ${MAX_NAME} characters.` };
682
682
  return null;
683
683
  }
684
+ var MAX_ORGANIZATION = 120;
685
+ function checkOrganization(value, required = false) {
686
+ const v = typeof value === "string" ? value.trim() : "";
687
+ if (v === "") return required ? { field: "organization", code: "required", message: "Enter your company's name." } : null;
688
+ if (v.length > MAX_ORGANIZATION) return { field: "organization", code: "too_long", message: `Use at most ${MAX_ORGANIZATION} characters.` };
689
+ return null;
690
+ }
684
691
  function checkCode(value) {
685
692
  const v = typeof value === "string" ? value.trim() : "";
686
693
  if (v === "") return { field: "code", code: "required", message: "Enter the code." };
@@ -1290,6 +1297,8 @@ function createCauthy(given = {}) {
1290
1297
  return json({
1291
1298
  providers: list.map((p) => ({ id: String(p.provider ?? p.id ?? ""), name: String(p.label ?? p.name ?? p.provider ?? "") })).filter((p) => p.id !== ""),
1292
1299
  signUp: settings.data?.allow_signup !== false,
1300
+ // The application's system makes an organization per sign-up: the form asks the company's name.
1301
+ ...settings.data?.signup?.organization?.ask === true ? { organization: { ask: true, required: settings.data.signup.organization.required === true } } : {},
1293
1302
  // A sign-in link needs a page of the application to open.
1294
1303
  magicLink: settings.data?.allow_magic_link === true && pages.signIn !== void 0,
1295
1304
  passkey: place.error ? true : here || place.data?.on_cauthy === true,
@@ -1575,10 +1584,11 @@ function createCauthy(given = {}) {
1575
1584
  return json({ status: "sent", sentTo: String(res.data?.sent_to ?? ""), channel: String(res.data?.channel ?? "sms") });
1576
1585
  }
1577
1586
  if (route === "/sign-up/email") {
1578
- const bad = firstProblem(checkName(b.name), checkEmail(b.email), checkNewPassword(b.password));
1587
+ const bad = firstProblem(checkName(b.name), checkEmail(b.email), checkNewPassword(b.password), checkOrganization(b.organization));
1579
1588
  if (bad) return invalid(bad);
1580
1589
  const email = String(b.email).trim();
1581
- const made = await ask(request, "POST", "/v1/auth/register", { email, password: b.password, display_name: typeof b.name === "string" ? b.name.trim() : "" }, pages.verifyEmail);
1590
+ const organization = typeof b.organization === "string" && b.organization.trim() !== "" ? { organization: { name: b.organization.trim() } } : {};
1591
+ const made = await ask(request, "POST", "/v1/auth/register", { email, password: b.password, display_name: typeof b.name === "string" ? b.name.trim() : "", ...organization }, pages.verifyEmail);
1582
1592
  if (made.error) return problem(made.status, made.error.code, made.error.message);
1583
1593
  if (made.data?.verification_required === true) return json({ status: "verification_required", email });
1584
1594
  const res = await ask(request, "POST", "/v1/auth/login", { email, password: b.password });
@@ -1780,6 +1790,7 @@ function createCauthy(given = {}) {
1780
1790
  if (!isToken(b.token)) return badLink();
1781
1791
  const res = await ask(request, "POST", "/v1/auth/email/verify", { token: String(b.token) });
1782
1792
  if (res.error) return problem(res.status, res.error.code, res.error.message);
1793
+ if (res.data?.access_token) return signedIn(request, res.data);
1783
1794
  return json({ status: "verified" });
1784
1795
  }
1785
1796
  if (route === "/sign-in/passkey/begin") {