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/client.d.mts +12 -3
- package/dist/client.d.ts +12 -3
- package/dist/client.js +13 -1
- package/dist/client.js.map +1 -1
- package/dist/client.mjs +13 -1
- package/dist/client.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +16 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -4
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +13 -2
- package/dist/react.d.ts +13 -2
- package/dist/react.js +23 -5
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +23 -5
- package/dist/react.mjs.map +1 -1
- package/dist/svelte.d.mts +1 -1
- package/dist/svelte.d.ts +1 -1
- package/dist/svelte.js +13 -1
- package/dist/svelte.js.map +1 -1
- package/dist/svelte.mjs +13 -1
- package/dist/svelte.mjs.map +1 -1
- package/dist/{validate-B_iC-4y8.d.mts → validate-BTRit1O1.d.mts} +1 -1
- package/dist/{validate-B_iC-4y8.d.ts → validate-BTRit1O1.d.ts} +1 -1
- package/dist/vue.d.mts +1 -1
- package/dist/vue.d.ts +1 -1
- package/dist/vue.js +13 -1
- package/dist/vue.js.map +1 -1
- package/dist/vue.mjs +13 -1
- package/dist/vue.mjs.map +1 -1
- package/package.json +1 -1
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." };
|
|
@@ -1097,10 +1104,11 @@ function createCauthy(given = {}) {
|
|
|
1097
1104
|
const clientIp = given.clientIp ?? ((request) => request.headers.get("x-forwarded-for")?.split(",").pop()?.trim() || void 0);
|
|
1098
1105
|
let noProofUntil = 0;
|
|
1099
1106
|
async function passedOn(request) {
|
|
1107
|
+
if (Date.now() < noProofUntil) return {};
|
|
1100
1108
|
const ip = clientIp(request);
|
|
1101
|
-
if (!ip || Date.now() < noProofUntil) return {};
|
|
1102
1109
|
try {
|
|
1103
|
-
|
|
1110
|
+
const proof = { "x-cauthy-system-token": await ownSystem.token() };
|
|
1111
|
+
return ip ? { ...proof, "x-cauthy-client-ip": ip } : proof;
|
|
1104
1112
|
} catch {
|
|
1105
1113
|
noProofUntil = Date.now() + 5 * 6e4;
|
|
1106
1114
|
return {};
|
|
@@ -1241,6 +1249,8 @@ function createCauthy(given = {}) {
|
|
|
1241
1249
|
return json({
|
|
1242
1250
|
providers: list.map((p) => ({ id: String(p.provider ?? p.id ?? ""), name: String(p.label ?? p.name ?? p.provider ?? "") })).filter((p) => p.id !== ""),
|
|
1243
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 } } : {},
|
|
1244
1254
|
// A sign-in link needs a page of the application to open.
|
|
1245
1255
|
magicLink: settings.data?.allow_magic_link === true && pages.signIn !== void 0,
|
|
1246
1256
|
passkey: place.error ? true : here || place.data?.on_cauthy === true,
|
|
@@ -1526,10 +1536,11 @@ function createCauthy(given = {}) {
|
|
|
1526
1536
|
return json({ status: "sent", sentTo: String(res.data?.sent_to ?? ""), channel: String(res.data?.channel ?? "sms") });
|
|
1527
1537
|
}
|
|
1528
1538
|
if (route === "/sign-up/email") {
|
|
1529
|
-
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));
|
|
1530
1540
|
if (bad) return invalid(bad);
|
|
1531
1541
|
const email = String(b.email).trim();
|
|
1532
|
-
const
|
|
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);
|
|
1533
1544
|
if (made.error) return problem(made.status, made.error.code, made.error.message);
|
|
1534
1545
|
if (made.data?.verification_required === true) return json({ status: "verification_required", email });
|
|
1535
1546
|
const res = await ask(request, "POST", "/v1/auth/login", { email, password: b.password });
|
|
@@ -1731,6 +1742,7 @@ function createCauthy(given = {}) {
|
|
|
1731
1742
|
if (!isToken(b.token)) return badLink();
|
|
1732
1743
|
const res = await ask(request, "POST", "/v1/auth/email/verify", { token: String(b.token) });
|
|
1733
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);
|
|
1734
1746
|
return json({ status: "verified" });
|
|
1735
1747
|
}
|
|
1736
1748
|
if (route === "/sign-in/passkey/begin") {
|