cauthy-auth 0.23.0 → 0.24.1
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/cli.js +31 -8
- package/dist/client.js +9 -2
- package/dist/client.js.map +1 -1
- package/dist/client.mjs +9 -2
- package/dist/client.mjs.map +1 -1
- package/dist/index.js +39 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -14
- package/dist/index.mjs.map +1 -1
- package/dist/mcp.js +12 -3
- package/dist/mcp.js.map +1 -1
- package/dist/mcp.mjs +12 -3
- package/dist/mcp.mjs.map +1 -1
- package/dist/react.js +24 -4
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +24 -4
- package/dist/react.mjs.map +1 -1
- package/dist/svelte.js +9 -2
- package/dist/svelte.js.map +1 -1
- package/dist/svelte.mjs +9 -2
- package/dist/svelte.mjs.map +1 -1
- package/dist/theme.js +29 -4
- package/dist/theme.js.map +1 -1
- package/dist/theme.mjs +27 -4
- package/dist/theme.mjs.map +1 -1
- package/dist/vue.js +9 -2
- package/dist/vue.js.map +1 -1
- package/dist/vue.mjs +9 -2
- package/dist/vue.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react.mjs
CHANGED
|
@@ -79,6 +79,13 @@ function ceremonyError(e) {
|
|
|
79
79
|
return { code: "passkey_failed", message: "The passkey could not be used. Try again, or sign in another way." };
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
// src/url.ts
|
|
83
|
+
function withoutTrailingSlashes(s) {
|
|
84
|
+
let end = s.length;
|
|
85
|
+
while (end > 0 && s.charCodeAt(end - 1) === 47) end--;
|
|
86
|
+
return s.slice(0, end);
|
|
87
|
+
}
|
|
88
|
+
|
|
82
89
|
// src/theme.ts
|
|
83
90
|
function themeVariables(theme) {
|
|
84
91
|
const vars = {};
|
|
@@ -197,7 +204,7 @@ function loadGoogleIdentity() {
|
|
|
197
204
|
var PASSKEY_SECONDS = 300;
|
|
198
205
|
var UNAVAILABLE = { code: "unavailable", message: "Sign-in is unavailable right now. Try again in a moment." };
|
|
199
206
|
function createAuthClient(options = {}) {
|
|
200
|
-
const base = (options.basePath ?? "/api/auth")
|
|
207
|
+
const base = withoutTrailingSlashes(options.basePath ?? "/api/auth");
|
|
201
208
|
const doFetch = (...args) => (options.fetch ?? fetch)(...args);
|
|
202
209
|
const locale = () => {
|
|
203
210
|
const said = typeof options.locale === "function" ? options.locale() : options.locale;
|
|
@@ -941,6 +948,16 @@ function useMethods(auth) {
|
|
|
941
948
|
function sitePath(to) {
|
|
942
949
|
return to && to.startsWith("/") && !to.startsWith("//") && !to.includes("\\") ? to : void 0;
|
|
943
950
|
}
|
|
951
|
+
function sameOrigin(to) {
|
|
952
|
+
const path = sitePath(to);
|
|
953
|
+
if (path || !to) return path;
|
|
954
|
+
try {
|
|
955
|
+
const url = new URL(to);
|
|
956
|
+
return url.origin === window.location.origin ? url.pathname + url.search + url.hash : void 0;
|
|
957
|
+
} catch {
|
|
958
|
+
return void 0;
|
|
959
|
+
}
|
|
960
|
+
}
|
|
944
961
|
function useForm(props) {
|
|
945
962
|
const t = { ...TEXTS[props.locale ?? "en"], ...props.texts, errors: { ...TEXTS[props.locale ?? "en"].errors, ...props.texts?.errors } };
|
|
946
963
|
const cx = (slot) => props.classNames?.[slot] ?? `cauthy-${slot}`;
|
|
@@ -951,7 +968,7 @@ function useForm(props) {
|
|
|
951
968
|
const say = (e) => t.errors[e.code] ?? e.message;
|
|
952
969
|
const done = (to) => {
|
|
953
970
|
if (props.onSuccess) props.onSuccess();
|
|
954
|
-
else window.location.assign(sitePath(to) ?? props.returnTo ?? "/");
|
|
971
|
+
else window.location.assign(sitePath(to) ?? sameOrigin(props.returnTo) ?? "/");
|
|
955
972
|
};
|
|
956
973
|
const root = useRoot(props);
|
|
957
974
|
return { t, cx, Button, Input, error, setError, busy, setBusy, say, done, root };
|
|
@@ -1213,7 +1230,10 @@ function GoogleOneTap(props) {
|
|
|
1213
1230
|
void auth.signIn.googleOneTap({ signal: ctl.signal, context: props.context }).then((r) => {
|
|
1214
1231
|
if (!r.ok || ctl.signal.aborted) return;
|
|
1215
1232
|
if (props.onSuccess) props.onSuccess();
|
|
1216
|
-
else
|
|
1233
|
+
else {
|
|
1234
|
+
const to = sameOrigin(props.returnTo);
|
|
1235
|
+
if (to) window.location.assign(to);
|
|
1236
|
+
}
|
|
1217
1237
|
});
|
|
1218
1238
|
return () => ctl.abort();
|
|
1219
1239
|
}, [unauthenticated]);
|
|
@@ -1862,7 +1882,7 @@ import { jsx as jsx2 } from "react/jsx-runtime";
|
|
|
1862
1882
|
var Ctx = createContext(null);
|
|
1863
1883
|
var AHEAD_MS = 6e4;
|
|
1864
1884
|
function CauthyProvider({ children, basePath = "/api/auth", initialSession }) {
|
|
1865
|
-
const base = basePath
|
|
1885
|
+
const base = withoutTrailingSlashes(basePath);
|
|
1866
1886
|
const [session, setSession] = useState2(initialSession ?? null);
|
|
1867
1887
|
const [status, setStatus] = useState2(
|
|
1868
1888
|
initialSession === void 0 ? "loading" : initialSession === null ? "unauthenticated" : "authenticated"
|