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.mjs CHANGED
@@ -633,6 +633,13 @@ function checkName(value) {
633
633
  if (typeof value !== "string" || value.trim().length > MAX_NAME) return { field: "name", code: "too_long", message: `Use at most ${MAX_NAME} characters.` };
634
634
  return null;
635
635
  }
636
+ var MAX_ORGANIZATION = 120;
637
+ function checkOrganization(value, required = false) {
638
+ const v = typeof value === "string" ? value.trim() : "";
639
+ if (v === "") return required ? { field: "organization", code: "required", message: "Enter your company's name." } : null;
640
+ if (v.length > MAX_ORGANIZATION) return { field: "organization", code: "too_long", message: `Use at most ${MAX_ORGANIZATION} characters.` };
641
+ return null;
642
+ }
636
643
  function checkCode(value) {
637
644
  const v = typeof value === "string" ? value.trim() : "";
638
645
  if (v === "") return { field: "code", code: "required", message: "Enter the code." };
@@ -1242,6 +1249,8 @@ function createCauthy(given = {}) {
1242
1249
  return json({
1243
1250
  providers: list.map((p) => ({ id: String(p.provider ?? p.id ?? ""), name: String(p.label ?? p.name ?? p.provider ?? "") })).filter((p) => p.id !== ""),
1244
1251
  signUp: settings.data?.allow_signup !== false,
1252
+ // The application's system makes an organization per sign-up: the form asks the company's name.
1253
+ ...settings.data?.signup?.organization?.ask === true ? { organization: { ask: true, required: settings.data.signup.organization.required === true } } : {},
1245
1254
  // A sign-in link needs a page of the application to open.
1246
1255
  magicLink: settings.data?.allow_magic_link === true && pages.signIn !== void 0,
1247
1256
  passkey: place.error ? true : here || place.data?.on_cauthy === true,
@@ -1527,10 +1536,11 @@ function createCauthy(given = {}) {
1527
1536
  return json({ status: "sent", sentTo: String(res.data?.sent_to ?? ""), channel: String(res.data?.channel ?? "sms") });
1528
1537
  }
1529
1538
  if (route === "/sign-up/email") {
1530
- const bad = firstProblem(checkName(b.name), checkEmail(b.email), checkNewPassword(b.password));
1539
+ const bad = firstProblem(checkName(b.name), checkEmail(b.email), checkNewPassword(b.password), checkOrganization(b.organization));
1531
1540
  if (bad) return invalid(bad);
1532
1541
  const email = String(b.email).trim();
1533
- const made = await ask(request, "POST", "/v1/auth/register", { email, password: b.password, display_name: typeof b.name === "string" ? b.name.trim() : "" }, pages.verifyEmail);
1542
+ const organization = typeof b.organization === "string" && b.organization.trim() !== "" ? { organization: { name: b.organization.trim() } } : {};
1543
+ 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);
1534
1544
  if (made.error) return problem(made.status, made.error.code, made.error.message);
1535
1545
  if (made.data?.verification_required === true) return json({ status: "verification_required", email });
1536
1546
  const res = await ask(request, "POST", "/v1/auth/login", { email, password: b.password });
@@ -1732,6 +1742,7 @@ function createCauthy(given = {}) {
1732
1742
  if (!isToken(b.token)) return badLink();
1733
1743
  const res = await ask(request, "POST", "/v1/auth/email/verify", { token: String(b.token) });
1734
1744
  if (res.error) return problem(res.status, res.error.code, res.error.message);
1745
+ if (res.data?.access_token) return signedIn(request, res.data);
1735
1746
  return json({ status: "verified" });
1736
1747
  }
1737
1748
  if (route === "/sign-in/passkey/begin") {