@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.d.cts
CHANGED
|
@@ -8,7 +8,7 @@ import { InsforgeUser, OAuthProvider, OAuthProviderConfig } from './types.cjs';
|
|
|
8
8
|
export { AuthConfig, EmailVerificationMethod } from './types.cjs';
|
|
9
9
|
import { CreateSessionResponse, CreateUserResponse, ResetPasswordResponse, GetPublicAuthConfigResponse } from '@insforge/shared-schemas';
|
|
10
10
|
export { useAuth, usePublicAuthConfig, useUser } from './hooks.cjs';
|
|
11
|
-
export { checkPasswordStrength, createPasswordSchema, emailSchema, passwordSchema, validateEmail, validatePassword } from './lib.cjs';
|
|
11
|
+
export { checkPasswordStrength, createPasswordSchema, emailSchema, passwordSchema, resolveAuthPath, resolveAuthUrl, validateEmail, validatePassword } from './lib.cjs';
|
|
12
12
|
export { getInsforgeRoutes } from './router.cjs';
|
|
13
13
|
import 'zod';
|
|
14
14
|
import 'react-router-dom';
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { InsforgeUser, OAuthProvider, OAuthProviderConfig } from './types.js';
|
|
|
8
8
|
export { AuthConfig, EmailVerificationMethod } from './types.js';
|
|
9
9
|
import { CreateSessionResponse, CreateUserResponse, ResetPasswordResponse, GetPublicAuthConfigResponse } from '@insforge/shared-schemas';
|
|
10
10
|
export { useAuth, usePublicAuthConfig, useUser } from './hooks.js';
|
|
11
|
-
export { checkPasswordStrength, createPasswordSchema, emailSchema, passwordSchema, validateEmail, validatePassword } from './lib.js';
|
|
11
|
+
export { checkPasswordStrength, createPasswordSchema, emailSchema, passwordSchema, resolveAuthPath, resolveAuthUrl, validateEmail, validatePassword } from './lib.js';
|
|
12
12
|
export { getInsforgeRoutes } from './router.js';
|
|
13
13
|
import 'zod';
|
|
14
14
|
import 'react-router-dom';
|
package/dist/index.js
CHANGED
|
@@ -12,7 +12,7 @@ if (typeof document !== 'undefined' && typeof window !== 'undefined') {
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
import { createContext, useState, useRef, useCallback, useEffect, useContext } from 'react';
|
|
15
|
+
import { createContext, useState, useRef, useCallback, useEffect, useContext, useMemo } from 'react';
|
|
16
16
|
import { useSearchParams } from 'react-router-dom';
|
|
17
17
|
import { createClient } from '@insforge/sdk';
|
|
18
18
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
@@ -558,6 +558,28 @@ function createRequirements(config) {
|
|
|
558
558
|
}
|
|
559
559
|
return requirements;
|
|
560
560
|
}
|
|
561
|
+
|
|
562
|
+
// src/lib/path-utils.ts
|
|
563
|
+
function resolveAuthPath(targetPath) {
|
|
564
|
+
if (typeof window === "undefined") {
|
|
565
|
+
return targetPath;
|
|
566
|
+
}
|
|
567
|
+
const currentPath = window.location.pathname;
|
|
568
|
+
if (currentPath.startsWith("/auth/")) {
|
|
569
|
+
if (targetPath.startsWith("/auth/")) {
|
|
570
|
+
return targetPath;
|
|
571
|
+
}
|
|
572
|
+
return `/auth${targetPath}`;
|
|
573
|
+
}
|
|
574
|
+
return targetPath;
|
|
575
|
+
}
|
|
576
|
+
function resolveAuthUrl(targetPath, searchParams) {
|
|
577
|
+
const resolvedPath = resolveAuthPath(targetPath);
|
|
578
|
+
if (!searchParams || searchParams.toString() === "") {
|
|
579
|
+
return resolvedPath;
|
|
580
|
+
}
|
|
581
|
+
return `${resolvedPath}?${searchParams.toString()}`;
|
|
582
|
+
}
|
|
561
583
|
function AuthPasswordField({
|
|
562
584
|
label,
|
|
563
585
|
id,
|
|
@@ -570,6 +592,10 @@ function AuthPasswordField({
|
|
|
570
592
|
}) {
|
|
571
593
|
const [showPassword, setShowPassword] = useState(false);
|
|
572
594
|
const [showStrength, setShowStrength] = useState(false);
|
|
595
|
+
const resolvedForgotPasswordHref = useMemo(
|
|
596
|
+
() => forgotPasswordLink ? resolveAuthPath(forgotPasswordLink.href) : void 0,
|
|
597
|
+
[forgotPasswordLink]
|
|
598
|
+
);
|
|
573
599
|
const handleFocus = (e) => {
|
|
574
600
|
if (showStrengthIndicator) {
|
|
575
601
|
setShowStrength(true);
|
|
@@ -579,7 +605,7 @@ function AuthPasswordField({
|
|
|
579
605
|
return /* @__PURE__ */ jsxs("div", { className: "if-passwordField if-internal-p5w9m7", children: [
|
|
580
606
|
(label || forgotPasswordLink) && /* @__PURE__ */ jsxs("div", { className: "if-passwordField-labelRow", children: [
|
|
581
607
|
/* @__PURE__ */ jsx("label", { htmlFor: id, className: "if-passwordField-label", children: label }),
|
|
582
|
-
forgotPasswordLink && /* @__PURE__ */ jsx("a", { href:
|
|
608
|
+
forgotPasswordLink && resolvedForgotPasswordHref && /* @__PURE__ */ jsx("a", { href: resolvedForgotPasswordHref, className: "if-passwordField-forgotLink", children: forgotPasswordLink.text || "Forget Password?" })
|
|
583
609
|
] }),
|
|
584
610
|
/* @__PURE__ */ jsxs("div", { className: "if-passwordField-inputWrapper", children: [
|
|
585
611
|
/* @__PURE__ */ jsx(
|
|
@@ -632,19 +658,7 @@ function AuthSubmitButton({
|
|
|
632
658
|
}
|
|
633
659
|
function AuthLink({ text, linkText, href }) {
|
|
634
660
|
const [searchParams] = useSearchParams();
|
|
635
|
-
const
|
|
636
|
-
const finalHref = (() => {
|
|
637
|
-
if (!currentSearch) {
|
|
638
|
-
return href;
|
|
639
|
-
}
|
|
640
|
-
try {
|
|
641
|
-
const url = new URL(href, window.location.origin);
|
|
642
|
-
url.search = currentSearch;
|
|
643
|
-
return url.pathname + url.search;
|
|
644
|
-
} catch {
|
|
645
|
-
return href;
|
|
646
|
-
}
|
|
647
|
-
})();
|
|
661
|
+
const finalHref = resolveAuthUrl(href, searchParams);
|
|
648
662
|
return /* @__PURE__ */ jsxs("p", { className: "if-authLink if-internal-al5w9p", children: [
|
|
649
663
|
text && /* @__PURE__ */ jsx("span", { className: "if-authLink-text", children: text }),
|
|
650
664
|
text && " ",
|
|
@@ -1900,12 +1914,9 @@ function ForgotPassword({ onError, ...uiProps }) {
|
|
|
1900
1914
|
const result = await resetPassword(resetToken, newPassword);
|
|
1901
1915
|
if (result?.message) {
|
|
1902
1916
|
setSuccess(true);
|
|
1903
|
-
const signInUrl =
|
|
1904
|
-
searchParams.forEach((value, key) => {
|
|
1905
|
-
signInUrl.searchParams.set(key, value);
|
|
1906
|
-
});
|
|
1917
|
+
const signInUrl = resolveAuthUrl("/sign-in", searchParams);
|
|
1907
1918
|
setTimeout(() => {
|
|
1908
|
-
window.location.href = signInUrl
|
|
1919
|
+
window.location.href = signInUrl;
|
|
1909
1920
|
}, 2e3);
|
|
1910
1921
|
} else {
|
|
1911
1922
|
const errorMessage = "Failed to reset password";
|
|
@@ -2323,23 +2334,24 @@ function Protect({
|
|
|
2323
2334
|
onRedirect
|
|
2324
2335
|
}) {
|
|
2325
2336
|
const { isSignedIn, isLoaded, user } = useInsforge();
|
|
2337
|
+
const resolvedRedirectTo = useMemo(() => resolveAuthPath(redirectTo), [redirectTo]);
|
|
2326
2338
|
useEffect(() => {
|
|
2327
2339
|
if (isLoaded && !isSignedIn) {
|
|
2328
2340
|
if (onRedirect) {
|
|
2329
|
-
onRedirect(
|
|
2341
|
+
onRedirect(resolvedRedirectTo);
|
|
2330
2342
|
} else {
|
|
2331
|
-
window.location.href =
|
|
2343
|
+
window.location.href = resolvedRedirectTo;
|
|
2332
2344
|
}
|
|
2333
2345
|
} else if (isLoaded && isSignedIn && condition && user) {
|
|
2334
2346
|
if (!condition(user)) {
|
|
2335
2347
|
if (onRedirect) {
|
|
2336
|
-
onRedirect(
|
|
2348
|
+
onRedirect(resolvedRedirectTo);
|
|
2337
2349
|
} else {
|
|
2338
|
-
window.location.href =
|
|
2350
|
+
window.location.href = resolvedRedirectTo;
|
|
2339
2351
|
}
|
|
2340
2352
|
}
|
|
2341
2353
|
}
|
|
2342
|
-
}, [isLoaded, isSignedIn,
|
|
2354
|
+
}, [isLoaded, isSignedIn, resolvedRedirectTo, condition, user, onRedirect]);
|
|
2343
2355
|
if (!isLoaded) {
|
|
2344
2356
|
return fallback || /* @__PURE__ */ jsx("div", { className: "insforge-loading", children: "Loading..." });
|
|
2345
2357
|
}
|
|
@@ -2429,6 +2441,6 @@ function getInsforgeRoutes(config) {
|
|
|
2429
2441
|
return routes;
|
|
2430
2442
|
}
|
|
2431
2443
|
|
|
2432
|
-
export { AuthBranding, AuthContainer, AuthDivider, AuthEmailVerificationStep, AuthErrorBanner, AuthFormField, AuthHeader, AuthLink, AuthOAuthButton, AuthOAuthProviders, AuthPasswordField, AuthPasswordStrengthIndicator, AuthResetPasswordVerificationStep, AuthSubmitButton, AuthVerificationCodeInput, ForgotPassword, ForgotPasswordForm, InsforgeProvider, OAUTH_PROVIDER_CONFIG, Protect, ResetPassword, ResetPasswordForm, SignIn, SignInForm, SignUp, SignUpForm, SignedIn, SignedOut, UserButton, VerifyEmail, VerifyEmailStatus, checkPasswordStrength, createPasswordSchema, emailSchema, getAllProviderConfigs, getInsforgeRoutes, getProviderConfig, passwordSchema, useAuth, useInsforge, usePublicAuthConfig, useUser, validateEmail, validatePassword };
|
|
2444
|
+
export { AuthBranding, AuthContainer, AuthDivider, AuthEmailVerificationStep, AuthErrorBanner, AuthFormField, AuthHeader, AuthLink, AuthOAuthButton, AuthOAuthProviders, AuthPasswordField, AuthPasswordStrengthIndicator, AuthResetPasswordVerificationStep, AuthSubmitButton, AuthVerificationCodeInput, ForgotPassword, ForgotPasswordForm, InsforgeProvider, OAUTH_PROVIDER_CONFIG, Protect, ResetPassword, ResetPasswordForm, SignIn, SignInForm, SignUp, SignUpForm, SignedIn, SignedOut, UserButton, VerifyEmail, VerifyEmailStatus, checkPasswordStrength, createPasswordSchema, emailSchema, getAllProviderConfigs, getInsforgeRoutes, getProviderConfig, passwordSchema, resolveAuthPath, resolveAuthUrl, useAuth, useInsforge, usePublicAuthConfig, useUser, validateEmail, validatePassword };
|
|
2433
2445
|
//# sourceMappingURL=index.js.map
|
|
2434
2446
|
//# sourceMappingURL=index.js.map
|