cauthy-auth 0.18.0 → 0.20.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 +59 -1
- package/dist/client.d.ts +59 -1
- package/dist/client.js +13 -3
- package/dist/client.js.map +1 -1
- package/dist/client.mjs +13 -3
- package/dist/client.mjs.map +1 -1
- package/dist/index.js +52 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -4
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +64 -1
- package/dist/react.d.ts +64 -1
- package/dist/react.js +92 -26
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +92 -26
- 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 -3
- package/dist/svelte.js.map +1 -1
- package/dist/svelte.mjs +13 -3
- package/dist/svelte.mjs.map +1 -1
- package/dist/vue.d.mts +1 -1
- package/dist/vue.d.ts +1 -1
- package/dist/vue.js +13 -3
- package/dist/vue.js.map +1 -1
- package/dist/vue.mjs +13 -3
- package/dist/vue.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react.mjs
CHANGED
|
@@ -231,6 +231,11 @@ function createAuthClient(options = {}) {
|
|
|
231
231
|
}
|
|
232
232
|
const linkUrl = (provider, o = {}) => `${base}/me/identities/link/${encodeURIComponent(provider)}${o.returnTo ? `?return_to=${encodeURIComponent(o.returnTo)}` : ""}`;
|
|
233
233
|
const socialUrl = (provider, o = {}) => `${base}/sign-in/social/${encodeURIComponent(provider)}${o.returnTo ? `?return_to=${encodeURIComponent(o.returnTo)}` : ""}`;
|
|
234
|
+
const ssoUrl = (target, o = {}) => {
|
|
235
|
+
const q = new URLSearchParams("connection" in target ? { connection: target.connection } : { email: target.email.trim() });
|
|
236
|
+
if (o.returnTo) q.set("return_to", o.returnTo);
|
|
237
|
+
return `${base}/sign-in/sso?${q}`;
|
|
238
|
+
};
|
|
234
239
|
const passkeyUrl = (o = {}) => {
|
|
235
240
|
const q = new URLSearchParams({ method: "passkey" });
|
|
236
241
|
if (o.returnTo) q.set("return_to", o.returnTo);
|
|
@@ -242,11 +247,11 @@ function createAuthClient(options = {}) {
|
|
|
242
247
|
const res = await doFetch(`${base}/methods`, { credentials: "same-origin", headers: { accept: "application/json" } });
|
|
243
248
|
if (res.ok) {
|
|
244
249
|
const m = await res.json();
|
|
245
|
-
return { providers: [], signUp: true, magicLink: false, passkey: false, ...m, passkeyHere: m.passkeyHere === true, passkeyOnCauthy: m.passkeyOnCauthy ?? m.passkey === true };
|
|
250
|
+
return { providers: [], signUp: true, magicLink: false, passkey: false, ...m, passkeyHere: m.passkeyHere === true, passkeyOnCauthy: m.passkeyOnCauthy ?? m.passkey === true, sso: m.sso === true };
|
|
246
251
|
}
|
|
247
252
|
} catch {
|
|
248
253
|
}
|
|
249
|
-
return { providers: [], signUp: true, magicLink: false, passkey: false, passkeyHere: false, passkeyOnCauthy: false };
|
|
254
|
+
return { providers: [], signUp: true, magicLink: false, passkey: false, passkeyHere: false, passkeyOnCauthy: false, sso: false };
|
|
250
255
|
}
|
|
251
256
|
async function ceremony(begin, finish, form, run, more = {}) {
|
|
252
257
|
const begun = await post(begin, form, null);
|
|
@@ -344,6 +349,11 @@ function createAuthClient(options = {}) {
|
|
|
344
349
|
socialUrl,
|
|
345
350
|
social(provider, o) {
|
|
346
351
|
window.location.assign(socialUrl(provider, o));
|
|
352
|
+
},
|
|
353
|
+
ssoDiscover: (f) => post("/sign-in/sso/discover", { email: f.email.trim() }, checkEmail(f.email)),
|
|
354
|
+
ssoUrl,
|
|
355
|
+
sso(target, o) {
|
|
356
|
+
window.location.assign(ssoUrl(target, o));
|
|
347
357
|
}
|
|
348
358
|
},
|
|
349
359
|
signUp: {
|
|
@@ -402,7 +412,7 @@ function createAuthClient(options = {}) {
|
|
|
402
412
|
},
|
|
403
413
|
addPasskey(f = {}) {
|
|
404
414
|
if (!canUsePasskeys()) return Promise.resolve({ ok: false, error: { code: "passkey_unavailable", message: "This browser cannot make passkeys." } });
|
|
405
|
-
return ceremony("/me/passkeys/add/begin", "/me/passkeys/add/finish", { password: f.password ?? "" }, makePasskey, { name: f.name ?? "" });
|
|
415
|
+
return ceremony("/me/passkeys/add/begin", "/me/passkeys/add/finish", { password: f.password ?? "", ...f.kind ? { kind: f.kind } : {} }, makePasskey, { name: f.name ?? "" });
|
|
406
416
|
},
|
|
407
417
|
removePasskey: (id) => post("/me/passkeys/remove", { id }, null)
|
|
408
418
|
},
|
|
@@ -543,6 +553,9 @@ var TEXTS = {
|
|
|
543
553
|
passkeyName: "A name for this device (optional)",
|
|
544
554
|
addPasskey: "Add a passkey on this device",
|
|
545
555
|
removePasskey: "Remove",
|
|
556
|
+
addPasskeyDevice: "Add this device (fingerprint or face)",
|
|
557
|
+
addSecurityKey: "Add a security key",
|
|
558
|
+
passkeyKinds: { security_key: "Security key", synced: "Synced across your devices", device: "On this device only" },
|
|
546
559
|
passkeyAdded: "The passkey was added. Next time, sign in with it.",
|
|
547
560
|
passkeyUnnamed: "Passkey",
|
|
548
561
|
sessions: "Where you are signed in",
|
|
@@ -561,6 +574,7 @@ var TEXTS = {
|
|
|
561
574
|
linkWith: "Link",
|
|
562
575
|
unlink: "Unlink",
|
|
563
576
|
linked: "The account was linked.",
|
|
577
|
+
ssoOnly: "Your company signs you in to this account.",
|
|
564
578
|
errors: {
|
|
565
579
|
required: "This is required.",
|
|
566
580
|
invalid_email: "That does not look like an email address.",
|
|
@@ -589,7 +603,15 @@ var TEXTS = {
|
|
|
589
603
|
captcha_failed: "The check that you are not a bot did not pass. Try it again.",
|
|
590
604
|
passkey_failed: "The passkey could not be used. Try again, or sign in another way.",
|
|
591
605
|
passkey_exists: "This device already has a passkey for your account.",
|
|
592
|
-
passkey_unavailable: "Passkeys cannot be used here."
|
|
606
|
+
passkey_unavailable: "Passkeys cannot be used here.",
|
|
607
|
+
sso_required: "This address signs in through its company.",
|
|
608
|
+
sso_not_found: "No company sign-in answers for this address.",
|
|
609
|
+
sso_failed: "The sign-in with your company could not be completed. Try again.",
|
|
610
|
+
sso_unavailable: "Your company's sign-in cannot be reached right now. Try again in a moment.",
|
|
611
|
+
invalid_assertion: "Your company's answer could not be checked. Try again.",
|
|
612
|
+
provisioning_disabled: "Your company's sign-in worked, but this workspace has no account for you. Ask its admin to add you.",
|
|
613
|
+
connection_inactive: "Your company's sign-in is turned off for this workspace.",
|
|
614
|
+
invalid_grant: "That sign-in expired. Try again."
|
|
593
615
|
}
|
|
594
616
|
},
|
|
595
617
|
es: {
|
|
@@ -655,6 +677,9 @@ var TEXTS = {
|
|
|
655
677
|
passkeyName: "Un nombre para este dispositivo (opcional)",
|
|
656
678
|
addPasskey: "Agregar una llave en este dispositivo",
|
|
657
679
|
removePasskey: "Quitar",
|
|
680
|
+
addPasskeyDevice: "Agregar este dispositivo (huella o rostro)",
|
|
681
|
+
addSecurityKey: "Agregar una llave f\xEDsica",
|
|
682
|
+
passkeyKinds: { security_key: "Llave f\xEDsica", synced: "Sincronizada entre tus dispositivos", device: "Solo en un dispositivo" },
|
|
658
683
|
passkeyAdded: "La llave de acceso qued\xF3 agregada. La pr\xF3xima vez, entra con ella.",
|
|
659
684
|
passkeyUnnamed: "Llave de acceso",
|
|
660
685
|
sessions: "D\xF3nde tienes la sesi\xF3n abierta",
|
|
@@ -673,6 +698,7 @@ var TEXTS = {
|
|
|
673
698
|
linkWith: "Vincular",
|
|
674
699
|
unlink: "Desvincular",
|
|
675
700
|
linked: "La cuenta qued\xF3 vinculada.",
|
|
701
|
+
ssoOnly: "A esta cuenta entras con el inicio de sesi\xF3n de tu empresa.",
|
|
676
702
|
errors: {
|
|
677
703
|
required: "Este dato es obligatorio.",
|
|
678
704
|
invalid_email: "Eso no parece un correo.",
|
|
@@ -701,7 +727,15 @@ var TEXTS = {
|
|
|
701
727
|
captcha_failed: "La verificaci\xF3n de que no eres un robot no pas\xF3. Int\xE9ntalo de nuevo.",
|
|
702
728
|
passkey_failed: "No se pudo usar la llave de acceso. Intenta de nuevo o entra de otra forma.",
|
|
703
729
|
passkey_exists: "Este dispositivo ya tiene una llave de acceso de tu cuenta.",
|
|
704
|
-
passkey_unavailable: "Aqu\xED no se pueden usar llaves de acceso."
|
|
730
|
+
passkey_unavailable: "Aqu\xED no se pueden usar llaves de acceso.",
|
|
731
|
+
sso_required: "Este correo entra con el inicio de sesi\xF3n de su empresa.",
|
|
732
|
+
sso_not_found: "Ninguna empresa usa inicio de sesi\xF3n propio con este correo.",
|
|
733
|
+
sso_failed: "No se pudo completar el ingreso con tu empresa. Intenta de nuevo.",
|
|
734
|
+
sso_unavailable: "Ahora no se puede llegar al inicio de sesi\xF3n de tu empresa. Intenta en un momento.",
|
|
735
|
+
invalid_assertion: "No se pudo verificar la respuesta de tu empresa. Intenta de nuevo.",
|
|
736
|
+
provisioning_disabled: "El ingreso con tu empresa funcion\xF3, pero este workspace no tiene una cuenta para ti. P\xEDdele a su admin que te agregue.",
|
|
737
|
+
connection_inactive: "El inicio de sesi\xF3n de tu empresa est\xE1 apagado en este workspace.",
|
|
738
|
+
invalid_grant: "Ese ingreso venci\xF3. Intenta de nuevo."
|
|
705
739
|
}
|
|
706
740
|
}
|
|
707
741
|
};
|
|
@@ -894,6 +928,25 @@ function SignIn(props) {
|
|
|
894
928
|
};
|
|
895
929
|
const autofill = useRef(null);
|
|
896
930
|
const [offer, setOffer] = useState(0);
|
|
931
|
+
const [company, setCompany] = useState(null);
|
|
932
|
+
useEffect(() => {
|
|
933
|
+
if (!methods?.sso || checkEmail(email) !== null) return setCompany(null);
|
|
934
|
+
let current = true;
|
|
935
|
+
const t = setTimeout(() => {
|
|
936
|
+
void auth.signIn.ssoDiscover({ email }).then((r) => {
|
|
937
|
+
if (current) setCompany(r.ok && r.status === "found" ? r.connection : null);
|
|
938
|
+
});
|
|
939
|
+
}, 350);
|
|
940
|
+
return () => {
|
|
941
|
+
current = false;
|
|
942
|
+
clearTimeout(t);
|
|
943
|
+
};
|
|
944
|
+
}, [email, methods]);
|
|
945
|
+
const toCompany = () => {
|
|
946
|
+
autofill.current?.abort();
|
|
947
|
+
f.setBusy(true);
|
|
948
|
+
auth.signIn.sso({ email }, { returnTo: props.returnTo });
|
|
949
|
+
};
|
|
897
950
|
useEffect(() => {
|
|
898
951
|
void auth.methods().then(setMethods);
|
|
899
952
|
const back = returnedError();
|
|
@@ -926,9 +979,11 @@ function SignIn(props) {
|
|
|
926
979
|
autofill.current?.abort();
|
|
927
980
|
f.setBusy(true);
|
|
928
981
|
f.setError(null);
|
|
982
|
+
if (step === "password" && company?.enforced) return toCompany();
|
|
929
983
|
const r = step === "code" ? await auth.signIn.mfa({ code }) : step === "sent" ? await auth.signIn.emailCode({ code }) : await auth.signIn.email({ email, password, captchaToken: challenge.token });
|
|
930
984
|
f.setBusy(false);
|
|
931
985
|
if (step === "password") challenge.renew();
|
|
986
|
+
if (!r.ok && r.error.code === "sso_required") return toCompany();
|
|
932
987
|
if (!r.ok) {
|
|
933
988
|
setOffer((n) => n + 1);
|
|
934
989
|
return f.setError(r.error);
|
|
@@ -954,6 +1009,7 @@ function SignIn(props) {
|
|
|
954
1009
|
const r = await auth.signIn.magicLink({ email, captchaToken: challenge.token, create: props.createAccounts, returnTo: props.returnTo });
|
|
955
1010
|
f.setBusy(false);
|
|
956
1011
|
challenge.renew();
|
|
1012
|
+
if (!r.ok && r.error.code === "sso_required") return toCompany();
|
|
957
1013
|
if (!r.ok) return f.setError(r.error);
|
|
958
1014
|
setStep("sent");
|
|
959
1015
|
};
|
|
@@ -988,23 +1044,31 @@ function SignIn(props) {
|
|
|
988
1044
|
methods?.passkey && /* @__PURE__ */ jsx(f.Button, { type: "button", disabled: f.busy, className: f.cx("providerButton"), onClick: () => void usePasskey(), children: f.t.usePasskey }),
|
|
989
1045
|
((methods?.providers.length ?? 0) > 0 || methods?.passkey) && /* @__PURE__ */ jsx("p", { className: f.cx("separator"), children: f.t.orWithEmail }),
|
|
990
1046
|
/* @__PURE__ */ jsx(Field, { f, name: "email", type: "email", label: f.t.email, value: email, autoComplete: methods?.passkeyHere ? "username webauthn" : "username", required: true, onChange: setEmail }),
|
|
991
|
-
/* @__PURE__ */
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1047
|
+
company && /* @__PURE__ */ jsxs(f.Button, { type: "button", disabled: f.busy, className: f.cx(company.enforced ? "button" : "providerButton"), onClick: toCompany, children: [
|
|
1048
|
+
f.t.continueWith,
|
|
1049
|
+
" ",
|
|
1050
|
+
company.name
|
|
1051
|
+
] }),
|
|
1052
|
+
company?.enforced && /* @__PURE__ */ jsx("p", { className: f.cx("notice"), children: f.t.ssoOnly }),
|
|
1053
|
+
!company?.enforced && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1054
|
+
/* @__PURE__ */ jsx(
|
|
1055
|
+
Field,
|
|
1056
|
+
{
|
|
1057
|
+
f,
|
|
1058
|
+
name: "password",
|
|
1059
|
+
type: "password",
|
|
1060
|
+
label: f.t.password,
|
|
1061
|
+
value: password,
|
|
1062
|
+
autoComplete: "current-password",
|
|
1063
|
+
required: true,
|
|
1064
|
+
onChange: setPassword,
|
|
1065
|
+
aside: props.links?.forgotPassword ? /* @__PURE__ */ jsx("a", { className: f.cx("link"), href: props.links.forgotPassword, children: f.t.forgotPassword }) : void 0
|
|
1066
|
+
}
|
|
1067
|
+
),
|
|
1068
|
+
challenge.node,
|
|
1069
|
+
/* @__PURE__ */ jsx(f.Button, { type: "submit", disabled: f.busy, className: f.cx("button"), children: f.t.signIn })
|
|
1070
|
+
] }),
|
|
1071
|
+
methods?.magicLink && !company?.enforced && /* @__PURE__ */ jsx(f.Button, { type: "button", disabled: f.busy, className: f.cx("providerButton"), onClick: () => void sendLink(), children: f.t.emailMeALink }),
|
|
1008
1072
|
methods?.signUp !== false && props.links?.signUp && /* @__PURE__ */ jsxs("p", { className: f.cx("footer"), children: [
|
|
1009
1073
|
f.t.noAccount,
|
|
1010
1074
|
" ",
|
|
@@ -1230,9 +1294,9 @@ function PasskeysPart({ props, account, accountUrl, when }) {
|
|
|
1230
1294
|
/* @__PURE__ */ jsx("a", { className: f.cx("link"), href: accountUrl, children: f.t.managePasskeys })
|
|
1231
1295
|
] });
|
|
1232
1296
|
}
|
|
1233
|
-
const add = async (e) => {
|
|
1234
|
-
e
|
|
1235
|
-
const r = await run(() => auth.account.addPasskey({ name, password }));
|
|
1297
|
+
const add = async (e, kind = "device") => {
|
|
1298
|
+
e?.preventDefault();
|
|
1299
|
+
const r = await run(() => auth.account.addPasskey({ name, password, kind }));
|
|
1236
1300
|
if (!r.ok) {
|
|
1237
1301
|
if (r.error.code === "cancelled") f.setError(null);
|
|
1238
1302
|
return;
|
|
@@ -1252,6 +1316,7 @@ function PasskeysPart({ props, account, accountUrl, when }) {
|
|
|
1252
1316
|
general && /* @__PURE__ */ jsx("p", { role: "alert", className: f.cx("error"), children: f.say(general) }),
|
|
1253
1317
|
list.length === 0 ? /* @__PURE__ */ jsx("p", { className: f.cx("notice"), children: f.t.noPasskeys }) : /* @__PURE__ */ jsx("ul", { className: f.cx("sessions"), children: list.map((p) => /* @__PURE__ */ jsxs("li", { className: f.cx("session"), children: [
|
|
1254
1318
|
p.name || f.t.passkeyUnnamed,
|
|
1319
|
+
p.kind !== "unknown" ? ` \xB7 ${f.t.passkeyKinds[p.kind]}` : "",
|
|
1255
1320
|
" \xB7 ",
|
|
1256
1321
|
when(p.createdAt),
|
|
1257
1322
|
" ",
|
|
@@ -1259,7 +1324,8 @@ function PasskeysPart({ props, account, accountUrl, when }) {
|
|
|
1259
1324
|
] }, p.id)) }),
|
|
1260
1325
|
/* @__PURE__ */ jsx(Field, { f, name: "name", type: "text", label: f.t.passkeyName, value: name, autoComplete: "off", onChange: setName }),
|
|
1261
1326
|
account.hasPassword && /* @__PURE__ */ jsx(Field, { f, name: "password", type: "password", label: f.t.currentPassword, value: password, autoComplete: "current-password", required: true, onChange: setPassword }),
|
|
1262
|
-
/* @__PURE__ */ jsx(f.Button, { type: "submit", disabled: f.busy, className: f.cx("button"), children: f.t.
|
|
1327
|
+
/* @__PURE__ */ jsx(f.Button, { type: "submit", disabled: f.busy, className: f.cx("button"), children: f.t.addPasskeyDevice }),
|
|
1328
|
+
/* @__PURE__ */ jsx(f.Button, { type: "button", disabled: f.busy, className: f.cx("providerButton"), onClick: () => void add(null, "security_key"), children: f.t.addSecurityKey }),
|
|
1263
1329
|
done && /* @__PURE__ */ jsx("p", { role: "status", className: f.cx("notice"), children: done })
|
|
1264
1330
|
] });
|
|
1265
1331
|
}
|