cauthy-auth 0.16.0 → 0.18.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 +15 -2
- package/dist/client.d.ts +15 -2
- package/dist/client.js +3 -2
- package/dist/client.js.map +1 -1
- package/dist/client.mjs +3 -2
- package/dist/client.mjs.map +1 -1
- package/dist/index.js +9 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -6
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +21 -2
- package/dist/react.d.ts +21 -2
- package/dist/react.js +12 -8
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +12 -8
- package/dist/react.mjs.map +1 -1
- package/dist/svelte.js +3 -2
- package/dist/svelte.js.map +1 -1
- package/dist/svelte.mjs +3 -2
- package/dist/svelte.mjs.map +1 -1
- package/dist/vue.js +3 -2
- package/dist/vue.js.map +1 -1
- package/dist/vue.mjs +3 -2
- package/dist/vue.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react.mjs
CHANGED
|
@@ -265,14 +265,15 @@ function createAuthClient(options = {}) {
|
|
|
265
265
|
mfa: (f) => post("/sign-in/mfa", { code: f.code }, checkCode(f.code)),
|
|
266
266
|
mfaMethods: () => post("/sign-in/mfa/methods", {}, null),
|
|
267
267
|
mfaSendCode: () => post("/sign-in/mfa/send", {}, null),
|
|
268
|
-
magicLink: (f) => post("/sign-in/magic-link", { email: f.email }, checkEmail(f.email), f.captchaToken),
|
|
268
|
+
magicLink: (f) => post("/sign-in/magic-link", { email: f.email, ...f.create ? { create: true } : {}, ...f.returnTo ? { returnTo: f.returnTo } : {} }, checkEmail(f.email), f.captchaToken),
|
|
269
269
|
magicLinkVerify: (f) => post("/sign-in/magic-link/verify", { token: f.token }, null),
|
|
270
270
|
emailCode: (f) => post("/sign-in/email-code", { code: f.code }, checkCode(f.code)),
|
|
271
271
|
passkeyUrl,
|
|
272
272
|
async passkey(o) {
|
|
273
273
|
const m = await methods();
|
|
274
274
|
if (m.passkeyHere && canUsePasskeys()) {
|
|
275
|
-
const
|
|
275
|
+
const email = o?.email?.trim() ?? "";
|
|
276
|
+
const r = await ceremony("/sign-in/passkey/begin", "/sign-in/passkey/finish", email !== "" && checkEmail(email) === null ? { email } : {}, getPasskey);
|
|
276
277
|
if (r.ok || r.error.code !== "passkey_unavailable" || !m.passkeyOnCauthy) return r;
|
|
277
278
|
} else if (!m.passkeyOnCauthy) {
|
|
278
279
|
return { ok: false, error: { code: "passkey_unavailable", message: "Passkeys cannot be used here." } };
|
|
@@ -799,6 +800,9 @@ function useMethods(auth) {
|
|
|
799
800
|
}, []);
|
|
800
801
|
return methods;
|
|
801
802
|
}
|
|
803
|
+
function sitePath(to) {
|
|
804
|
+
return to && to.startsWith("/") && !to.startsWith("//") && !to.includes("\\") ? to : void 0;
|
|
805
|
+
}
|
|
802
806
|
function useForm(props) {
|
|
803
807
|
const t = { ...TEXTS[props.locale ?? "en"], ...props.texts, errors: { ...TEXTS[props.locale ?? "en"].errors, ...props.texts?.errors } };
|
|
804
808
|
const cx = (slot) => props.classNames?.[slot] ?? `cauthy-${slot}`;
|
|
@@ -807,9 +811,9 @@ function useForm(props) {
|
|
|
807
811
|
const [error, setError] = useState(null);
|
|
808
812
|
const [busy, setBusy] = useState(false);
|
|
809
813
|
const say = (e) => t.errors[e.code] ?? e.message;
|
|
810
|
-
const done = () => {
|
|
814
|
+
const done = (to) => {
|
|
811
815
|
if (props.onSuccess) props.onSuccess();
|
|
812
|
-
else window.location.assign(props.returnTo ?? "/");
|
|
816
|
+
else window.location.assign(sitePath(to) ?? props.returnTo ?? "/");
|
|
813
817
|
};
|
|
814
818
|
const root = useRoot(props);
|
|
815
819
|
return { t, cx, Button, Input, error, setError, busy, setBusy, say, done, root };
|
|
@@ -899,7 +903,7 @@ function SignIn(props) {
|
|
|
899
903
|
if (!token) return;
|
|
900
904
|
setStep("opening");
|
|
901
905
|
void auth.signIn.magicLinkVerify({ token }).then((r) => {
|
|
902
|
-
if (r.ok) return f.done();
|
|
906
|
+
if (r.ok) return f.done(new URLSearchParams(window.location.search).get("return_to") ?? void 0);
|
|
903
907
|
f.setError(r.error);
|
|
904
908
|
setStep("password");
|
|
905
909
|
});
|
|
@@ -930,13 +934,13 @@ function SignIn(props) {
|
|
|
930
934
|
return f.setError(r.error);
|
|
931
935
|
}
|
|
932
936
|
if (r.status === "mfa_required") return setStep("code");
|
|
933
|
-
f.done();
|
|
937
|
+
f.done("returnTo" in r && typeof r.returnTo === "string" ? r.returnTo : void 0);
|
|
934
938
|
};
|
|
935
939
|
const usePasskey = async () => {
|
|
936
940
|
autofill.current?.abort();
|
|
937
941
|
f.setBusy(true);
|
|
938
942
|
f.setError(null);
|
|
939
|
-
const r = await auth.signIn.passkey({ returnTo: props.returnTo, locale: props.locale });
|
|
943
|
+
const r = await auth.signIn.passkey({ returnTo: props.returnTo, locale: props.locale, email });
|
|
940
944
|
if (r.ok && r.status === "redirected") return;
|
|
941
945
|
f.setBusy(false);
|
|
942
946
|
if (!r.ok) setOffer((n) => n + 1);
|
|
@@ -947,7 +951,7 @@ function SignIn(props) {
|
|
|
947
951
|
autofill.current?.abort();
|
|
948
952
|
f.setBusy(true);
|
|
949
953
|
f.setError(null);
|
|
950
|
-
const r = await auth.signIn.magicLink({ email, captchaToken: challenge.token });
|
|
954
|
+
const r = await auth.signIn.magicLink({ email, captchaToken: challenge.token, create: props.createAccounts, returnTo: props.returnTo });
|
|
951
955
|
f.setBusy(false);
|
|
952
956
|
challenge.renew();
|
|
953
957
|
if (!r.ok) return f.setError(r.error);
|