@insforge/react 0.4.6 → 0.4.7
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/atoms.cjs +28 -14
- package/dist/atoms.cjs.map +1 -1
- package/dist/atoms.js +29 -15
- package/dist/atoms.js.map +1 -1
- package/dist/components.cjs +36 -24
- package/dist/components.cjs.map +1 -1
- package/dist/components.js +37 -25
- package/dist/components.js.map +1 -1
- package/dist/forms.cjs +28 -14
- package/dist/forms.cjs.map +1 -1
- package/dist/forms.js +29 -15
- package/dist/forms.js.map +1 -1
- package/dist/index.cjs +38 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +38 -26
- package/dist/index.js.map +1 -1
- package/dist/lib.cjs +24 -0
- package/dist/lib.cjs.map +1 -1
- package/dist/lib.d.cts +36 -1
- package/dist/lib.d.ts +36 -1
- package/dist/lib.js +23 -1
- package/dist/lib.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -560,6 +560,28 @@ function createRequirements(config) {
|
|
|
560
560
|
}
|
|
561
561
|
return requirements;
|
|
562
562
|
}
|
|
563
|
+
|
|
564
|
+
// src/lib/path-utils.ts
|
|
565
|
+
function resolveAuthPath(targetPath) {
|
|
566
|
+
if (typeof window === "undefined") {
|
|
567
|
+
return targetPath;
|
|
568
|
+
}
|
|
569
|
+
const currentPath = window.location.pathname;
|
|
570
|
+
if (currentPath.startsWith("/auth/")) {
|
|
571
|
+
if (targetPath.startsWith("/auth/")) {
|
|
572
|
+
return targetPath;
|
|
573
|
+
}
|
|
574
|
+
return `/auth${targetPath}`;
|
|
575
|
+
}
|
|
576
|
+
return targetPath;
|
|
577
|
+
}
|
|
578
|
+
function resolveAuthUrl(targetPath, searchParams) {
|
|
579
|
+
const resolvedPath = resolveAuthPath(targetPath);
|
|
580
|
+
if (!searchParams || searchParams.toString() === "") {
|
|
581
|
+
return resolvedPath;
|
|
582
|
+
}
|
|
583
|
+
return `${resolvedPath}?${searchParams.toString()}`;
|
|
584
|
+
}
|
|
563
585
|
function AuthPasswordField({
|
|
564
586
|
label,
|
|
565
587
|
id,
|
|
@@ -572,6 +594,10 @@ function AuthPasswordField({
|
|
|
572
594
|
}) {
|
|
573
595
|
const [showPassword, setShowPassword] = react.useState(false);
|
|
574
596
|
const [showStrength, setShowStrength] = react.useState(false);
|
|
597
|
+
const resolvedForgotPasswordHref = react.useMemo(
|
|
598
|
+
() => forgotPasswordLink ? resolveAuthPath(forgotPasswordLink.href) : void 0,
|
|
599
|
+
[forgotPasswordLink]
|
|
600
|
+
);
|
|
575
601
|
const handleFocus = (e) => {
|
|
576
602
|
if (showStrengthIndicator) {
|
|
577
603
|
setShowStrength(true);
|
|
@@ -581,7 +607,7 @@ function AuthPasswordField({
|
|
|
581
607
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-passwordField if-internal-p5w9m7", children: [
|
|
582
608
|
(label || forgotPasswordLink) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-passwordField-labelRow", children: [
|
|
583
609
|
/* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: id, className: "if-passwordField-label", children: label }),
|
|
584
|
-
forgotPasswordLink && /* @__PURE__ */ jsxRuntime.jsx("a", { href:
|
|
610
|
+
forgotPasswordLink && resolvedForgotPasswordHref && /* @__PURE__ */ jsxRuntime.jsx("a", { href: resolvedForgotPasswordHref, className: "if-passwordField-forgotLink", children: forgotPasswordLink.text || "Forget Password?" })
|
|
585
611
|
] }),
|
|
586
612
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "if-passwordField-inputWrapper", children: [
|
|
587
613
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -634,19 +660,7 @@ function AuthSubmitButton({
|
|
|
634
660
|
}
|
|
635
661
|
function AuthLink({ text, linkText, href }) {
|
|
636
662
|
const [searchParams] = reactRouterDom.useSearchParams();
|
|
637
|
-
const
|
|
638
|
-
const finalHref = (() => {
|
|
639
|
-
if (!currentSearch) {
|
|
640
|
-
return href;
|
|
641
|
-
}
|
|
642
|
-
try {
|
|
643
|
-
const url = new URL(href, window.location.origin);
|
|
644
|
-
url.search = currentSearch;
|
|
645
|
-
return url.pathname + url.search;
|
|
646
|
-
} catch {
|
|
647
|
-
return href;
|
|
648
|
-
}
|
|
649
|
-
})();
|
|
663
|
+
const finalHref = resolveAuthUrl(href, searchParams);
|
|
650
664
|
return /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "if-authLink if-internal-al5w9p", children: [
|
|
651
665
|
text && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "if-authLink-text", children: text }),
|
|
652
666
|
text && " ",
|
|
@@ -1902,12 +1916,9 @@ function ForgotPassword({ onError, ...uiProps }) {
|
|
|
1902
1916
|
const result = await resetPassword(resetToken, newPassword);
|
|
1903
1917
|
if (result?.message) {
|
|
1904
1918
|
setSuccess(true);
|
|
1905
|
-
const signInUrl =
|
|
1906
|
-
searchParams.forEach((value, key) => {
|
|
1907
|
-
signInUrl.searchParams.set(key, value);
|
|
1908
|
-
});
|
|
1919
|
+
const signInUrl = resolveAuthUrl("/sign-in", searchParams);
|
|
1909
1920
|
setTimeout(() => {
|
|
1910
|
-
window.location.href = signInUrl
|
|
1921
|
+
window.location.href = signInUrl;
|
|
1911
1922
|
}, 2e3);
|
|
1912
1923
|
} else {
|
|
1913
1924
|
const errorMessage = "Failed to reset password";
|
|
@@ -2325,23 +2336,24 @@ function Protect({
|
|
|
2325
2336
|
onRedirect
|
|
2326
2337
|
}) {
|
|
2327
2338
|
const { isSignedIn, isLoaded, user } = useInsforge();
|
|
2339
|
+
const resolvedRedirectTo = react.useMemo(() => resolveAuthPath(redirectTo), [redirectTo]);
|
|
2328
2340
|
react.useEffect(() => {
|
|
2329
2341
|
if (isLoaded && !isSignedIn) {
|
|
2330
2342
|
if (onRedirect) {
|
|
2331
|
-
onRedirect(
|
|
2343
|
+
onRedirect(resolvedRedirectTo);
|
|
2332
2344
|
} else {
|
|
2333
|
-
window.location.href =
|
|
2345
|
+
window.location.href = resolvedRedirectTo;
|
|
2334
2346
|
}
|
|
2335
2347
|
} else if (isLoaded && isSignedIn && condition && user) {
|
|
2336
2348
|
if (!condition(user)) {
|
|
2337
2349
|
if (onRedirect) {
|
|
2338
|
-
onRedirect(
|
|
2350
|
+
onRedirect(resolvedRedirectTo);
|
|
2339
2351
|
} else {
|
|
2340
|
-
window.location.href =
|
|
2352
|
+
window.location.href = resolvedRedirectTo;
|
|
2341
2353
|
}
|
|
2342
2354
|
}
|
|
2343
2355
|
}
|
|
2344
|
-
}, [isLoaded, isSignedIn,
|
|
2356
|
+
}, [isLoaded, isSignedIn, resolvedRedirectTo, condition, user, onRedirect]);
|
|
2345
2357
|
if (!isLoaded) {
|
|
2346
2358
|
return fallback || /* @__PURE__ */ jsxRuntime.jsx("div", { className: "insforge-loading", children: "Loading..." });
|
|
2347
2359
|
}
|
|
@@ -2469,6 +2481,8 @@ exports.getAllProviderConfigs = getAllProviderConfigs;
|
|
|
2469
2481
|
exports.getInsforgeRoutes = getInsforgeRoutes;
|
|
2470
2482
|
exports.getProviderConfig = getProviderConfig;
|
|
2471
2483
|
exports.passwordSchema = passwordSchema;
|
|
2484
|
+
exports.resolveAuthPath = resolveAuthPath;
|
|
2485
|
+
exports.resolveAuthUrl = resolveAuthUrl;
|
|
2472
2486
|
exports.useAuth = useAuth;
|
|
2473
2487
|
exports.useInsforge = useInsforge;
|
|
2474
2488
|
exports.usePublicAuthConfig = usePublicAuthConfig;
|