cauthy-auth 0.16.0 → 0.17.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 +11 -1
- package/dist/client.d.ts +11 -1
- package/dist/client.js +1 -1
- package/dist/client.js.map +1 -1
- package/dist/client.mjs +1 -1
- package/dist/client.mjs.map +1 -1
- package/dist/index.js +7 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -5
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +17 -1
- package/dist/react.d.ts +17 -1
- package/dist/react.js +9 -6
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +9 -6
- package/dist/react.mjs.map +1 -1
- package/dist/svelte.js +1 -1
- package/dist/svelte.js.map +1 -1
- package/dist/svelte.mjs +1 -1
- package/dist/svelte.mjs.map +1 -1
- package/dist/vue.js +1 -1
- package/dist/vue.js.map +1 -1
- package/dist/vue.mjs +1 -1
- package/dist/vue.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react.mjs
CHANGED
|
@@ -265,7 +265,7 @@ 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,
|
|
@@ -799,6 +799,9 @@ function useMethods(auth) {
|
|
|
799
799
|
}, []);
|
|
800
800
|
return methods;
|
|
801
801
|
}
|
|
802
|
+
function sitePath(to) {
|
|
803
|
+
return to && to.startsWith("/") && !to.startsWith("//") && !to.includes("\\") ? to : void 0;
|
|
804
|
+
}
|
|
802
805
|
function useForm(props) {
|
|
803
806
|
const t = { ...TEXTS[props.locale ?? "en"], ...props.texts, errors: { ...TEXTS[props.locale ?? "en"].errors, ...props.texts?.errors } };
|
|
804
807
|
const cx = (slot) => props.classNames?.[slot] ?? `cauthy-${slot}`;
|
|
@@ -807,9 +810,9 @@ function useForm(props) {
|
|
|
807
810
|
const [error, setError] = useState(null);
|
|
808
811
|
const [busy, setBusy] = useState(false);
|
|
809
812
|
const say = (e) => t.errors[e.code] ?? e.message;
|
|
810
|
-
const done = () => {
|
|
813
|
+
const done = (to) => {
|
|
811
814
|
if (props.onSuccess) props.onSuccess();
|
|
812
|
-
else window.location.assign(props.returnTo ?? "/");
|
|
815
|
+
else window.location.assign(sitePath(to) ?? props.returnTo ?? "/");
|
|
813
816
|
};
|
|
814
817
|
const root = useRoot(props);
|
|
815
818
|
return { t, cx, Button, Input, error, setError, busy, setBusy, say, done, root };
|
|
@@ -899,7 +902,7 @@ function SignIn(props) {
|
|
|
899
902
|
if (!token) return;
|
|
900
903
|
setStep("opening");
|
|
901
904
|
void auth.signIn.magicLinkVerify({ token }).then((r) => {
|
|
902
|
-
if (r.ok) return f.done();
|
|
905
|
+
if (r.ok) return f.done(new URLSearchParams(window.location.search).get("return_to") ?? void 0);
|
|
903
906
|
f.setError(r.error);
|
|
904
907
|
setStep("password");
|
|
905
908
|
});
|
|
@@ -930,7 +933,7 @@ function SignIn(props) {
|
|
|
930
933
|
return f.setError(r.error);
|
|
931
934
|
}
|
|
932
935
|
if (r.status === "mfa_required") return setStep("code");
|
|
933
|
-
f.done();
|
|
936
|
+
f.done("returnTo" in r && typeof r.returnTo === "string" ? r.returnTo : void 0);
|
|
934
937
|
};
|
|
935
938
|
const usePasskey = async () => {
|
|
936
939
|
autofill.current?.abort();
|
|
@@ -947,7 +950,7 @@ function SignIn(props) {
|
|
|
947
950
|
autofill.current?.abort();
|
|
948
951
|
f.setBusy(true);
|
|
949
952
|
f.setError(null);
|
|
950
|
-
const r = await auth.signIn.magicLink({ email, captchaToken: challenge.token });
|
|
953
|
+
const r = await auth.signIn.magicLink({ email, captchaToken: challenge.token, create: props.createAccounts, returnTo: props.returnTo });
|
|
951
954
|
f.setBusy(false);
|
|
952
955
|
challenge.renew();
|
|
953
956
|
if (!r.ok) return f.setError(r.error);
|