@insforge/react 0.5.6 → 0.5.8
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/README.md +51 -68
- package/dist/atoms.cjs.map +1 -1
- package/dist/atoms.js.map +1 -1
- package/dist/components.cjs +44 -0
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +49 -1
- package/dist/components.d.ts +49 -1
- package/dist/components.js +44 -2
- package/dist/components.js.map +1 -1
- package/dist/forms.cjs.map +1 -1
- package/dist/forms.js.map +1 -1
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +44 -91
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +44 -92
- package/dist/index.js.map +1 -1
- package/package.json +1 -6
- package/dist/routes.cjs +0 -132
- package/dist/routes.cjs.map +0 -1
- package/dist/routes.d.cts +0 -78
- package/dist/routes.d.ts +0 -78
- package/dist/routes.js +0 -130
- package/dist/routes.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { ConditionalProps, ForgotPassword, ForgotPasswordProps, Protect, ProtectProps, ResetPassword, ResetPasswordProps, SignIn, SignInProps, SignUp, SignUpProps, SignedIn, SignedOut, UserButton, UserButtonProps, VerifyEmail, VerifyEmailProps } from './components.cjs';
|
|
1
|
+
export { ConditionalProps, ForgotPassword, ForgotPasswordProps, Protect, ProtectProps, ResetPassword, ResetPasswordProps, SignIn, SignInButton, SignInButtonProps, SignInProps, SignUp, SignUpButton, SignUpButtonProps, SignUpProps, SignedIn, SignedOut, UserButton, UserButtonProps, VerifyEmail, VerifyEmailProps } from './components.cjs';
|
|
2
2
|
export { ForgotPasswordForm, ForgotPasswordFormProps, ResetPasswordForm, ResetPasswordFormProps, SignInForm, SignInFormProps, SignUpForm, SignUpFormProps, VerifyEmailStatus, VerifyEmailStatusProps } from './forms.cjs';
|
|
3
3
|
export { AuthBranding, AuthContainer, AuthContainerProps, AuthDivider, AuthDividerProps, AuthEmailVerificationStep, AuthErrorBanner, AuthErrorBannerProps, AuthFormField, AuthFormFieldProps, AuthHeader, AuthHeaderProps, AuthLink, AuthLinkProps, AuthOAuthButton, AuthOAuthButtonProps, AuthOAuthProviders, AuthOAuthProvidersProps, AuthPasswordField, AuthPasswordFieldProps, AuthPasswordStrengthIndicator, AuthPasswordStrengthIndicatorProps, AuthResetPasswordVerificationStep, AuthSubmitButton, AuthSubmitButtonProps, AuthVerificationCodeInput, AuthVerificationCodeInputProps } from './atoms.cjs';
|
|
4
4
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
@@ -10,7 +10,6 @@ import { CreateSessionResponse, CreateUserResponse, ResetPasswordResponse, GetPu
|
|
|
10
10
|
export { useAuth, usePublicAuthConfig, useUser } from './hooks.cjs';
|
|
11
11
|
export { checkPasswordStrength, createPasswordSchema, emailSchema, passwordSchema, resolveAuthPath, resolveAuthUrl, validateEmail, validatePassword } from './lib.cjs';
|
|
12
12
|
export { BrowserNavigationAdapter, NavigationAdapter, NavigationProvider, NavigationProviderProps, useNavigationAdapter, useSearchParams } from './navigation.cjs';
|
|
13
|
-
export { RouteGuard, RouteGuardProps } from './routes.cjs';
|
|
14
13
|
import 'zod';
|
|
15
14
|
|
|
16
15
|
interface InsforgeContextValue {
|
|
@@ -93,7 +92,6 @@ interface InsforgeProviderProps {
|
|
|
93
92
|
* return (
|
|
94
93
|
* <InsforgeProvider
|
|
95
94
|
* baseUrl={import.meta.env.VITE_INSFORGE_BASE_URL}
|
|
96
|
-
* afterSignInUrl="/dashboard"
|
|
97
95
|
* >
|
|
98
96
|
* {children}
|
|
99
97
|
* </InsforgeProvider>
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { ConditionalProps, ForgotPassword, ForgotPasswordProps, Protect, ProtectProps, ResetPassword, ResetPasswordProps, SignIn, SignInProps, SignUp, SignUpProps, SignedIn, SignedOut, UserButton, UserButtonProps, VerifyEmail, VerifyEmailProps } from './components.js';
|
|
1
|
+
export { ConditionalProps, ForgotPassword, ForgotPasswordProps, Protect, ProtectProps, ResetPassword, ResetPasswordProps, SignIn, SignInButton, SignInButtonProps, SignInProps, SignUp, SignUpButton, SignUpButtonProps, SignUpProps, SignedIn, SignedOut, UserButton, UserButtonProps, VerifyEmail, VerifyEmailProps } from './components.js';
|
|
2
2
|
export { ForgotPasswordForm, ForgotPasswordFormProps, ResetPasswordForm, ResetPasswordFormProps, SignInForm, SignInFormProps, SignUpForm, SignUpFormProps, VerifyEmailStatus, VerifyEmailStatusProps } from './forms.js';
|
|
3
3
|
export { AuthBranding, AuthContainer, AuthContainerProps, AuthDivider, AuthDividerProps, AuthEmailVerificationStep, AuthErrorBanner, AuthErrorBannerProps, AuthFormField, AuthFormFieldProps, AuthHeader, AuthHeaderProps, AuthLink, AuthLinkProps, AuthOAuthButton, AuthOAuthButtonProps, AuthOAuthProviders, AuthOAuthProvidersProps, AuthPasswordField, AuthPasswordFieldProps, AuthPasswordStrengthIndicator, AuthPasswordStrengthIndicatorProps, AuthResetPasswordVerificationStep, AuthSubmitButton, AuthSubmitButtonProps, AuthVerificationCodeInput, AuthVerificationCodeInputProps } from './atoms.js';
|
|
4
4
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
@@ -10,7 +10,6 @@ import { CreateSessionResponse, CreateUserResponse, ResetPasswordResponse, GetPu
|
|
|
10
10
|
export { useAuth, usePublicAuthConfig, useUser } from './hooks.js';
|
|
11
11
|
export { checkPasswordStrength, createPasswordSchema, emailSchema, passwordSchema, resolveAuthPath, resolveAuthUrl, validateEmail, validatePassword } from './lib.js';
|
|
12
12
|
export { BrowserNavigationAdapter, NavigationAdapter, NavigationProvider, NavigationProviderProps, useNavigationAdapter, useSearchParams } from './navigation.js';
|
|
13
|
-
export { RouteGuard, RouteGuardProps } from './routes.js';
|
|
14
13
|
import 'zod';
|
|
15
14
|
|
|
16
15
|
interface InsforgeContextValue {
|
|
@@ -93,7 +92,6 @@ interface InsforgeProviderProps {
|
|
|
93
92
|
* return (
|
|
94
93
|
* <InsforgeProvider
|
|
95
94
|
* baseUrl={import.meta.env.VITE_INSFORGE_BASE_URL}
|
|
96
|
-
* afterSignInUrl="/dashboard"
|
|
97
95
|
* >
|
|
98
96
|
* {children}
|
|
99
97
|
* </InsforgeProvider>
|
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, useContext, useState, useRef, useCallback, useEffect, useMemo } from 'react';
|
|
15
|
+
import { createContext, useContext, useState, useRef, useCallback, useEffect, useMemo, isValidElement, cloneElement } from 'react';
|
|
16
16
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
17
17
|
import { createClient } from '@insforge/sdk';
|
|
18
18
|
import { AlertTriangle, Check, EyeOff, Eye, Loader2, CircleCheck, LogOut } from 'lucide-react';
|
|
@@ -2457,6 +2457,48 @@ function SignedOut({ children }) {
|
|
|
2457
2457
|
}
|
|
2458
2458
|
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
2459
2459
|
}
|
|
2460
|
+
function SignInButton({ children, className }) {
|
|
2461
|
+
const { afterSignInUrl, baseUrl } = useInsforge();
|
|
2462
|
+
const handleClick = () => {
|
|
2463
|
+
const redirectUrl = new URL(afterSignInUrl, window.location.origin).href;
|
|
2464
|
+
const authUrl = new URL("/auth/sign-in", baseUrl);
|
|
2465
|
+
authUrl.searchParams.set("redirect", redirectUrl);
|
|
2466
|
+
window.location.replace(authUrl.toString());
|
|
2467
|
+
};
|
|
2468
|
+
if (children && isValidElement(children)) {
|
|
2469
|
+
const originalOnClick = children.props?.onClick;
|
|
2470
|
+
return cloneElement(children, {
|
|
2471
|
+
onClick: (e) => {
|
|
2472
|
+
handleClick();
|
|
2473
|
+
if (originalOnClick) {
|
|
2474
|
+
originalOnClick(e);
|
|
2475
|
+
}
|
|
2476
|
+
}
|
|
2477
|
+
});
|
|
2478
|
+
}
|
|
2479
|
+
return /* @__PURE__ */ jsx("button", { type: "button", className, onClick: handleClick, children: children || "Sign in" });
|
|
2480
|
+
}
|
|
2481
|
+
function SignUpButton({ children, className }) {
|
|
2482
|
+
const { afterSignInUrl, baseUrl } = useInsforge();
|
|
2483
|
+
const handleClick = () => {
|
|
2484
|
+
const redirectUrl = new URL(afterSignInUrl, window.location.origin).href;
|
|
2485
|
+
const authUrl = new URL("/auth/sign-up", baseUrl);
|
|
2486
|
+
authUrl.searchParams.set("redirect", redirectUrl);
|
|
2487
|
+
window.location.replace(authUrl.toString());
|
|
2488
|
+
};
|
|
2489
|
+
if (children && isValidElement(children)) {
|
|
2490
|
+
const originalOnClick = children.props?.onClick;
|
|
2491
|
+
return cloneElement(children, {
|
|
2492
|
+
onClick: (e) => {
|
|
2493
|
+
handleClick();
|
|
2494
|
+
if (originalOnClick) {
|
|
2495
|
+
originalOnClick(e);
|
|
2496
|
+
}
|
|
2497
|
+
}
|
|
2498
|
+
});
|
|
2499
|
+
}
|
|
2500
|
+
return /* @__PURE__ */ jsx("button", { type: "button", className, onClick: handleClick, children: children || "Sign up" });
|
|
2501
|
+
}
|
|
2460
2502
|
|
|
2461
2503
|
// src/hooks/useAuth.ts
|
|
2462
2504
|
function useAuth() {
|
|
@@ -2469,97 +2511,7 @@ function useUser() {
|
|
|
2469
2511
|
const { user, isLoaded, updateUser, setUser } = useInsforge();
|
|
2470
2512
|
return { user, isLoaded, updateUser, setUser };
|
|
2471
2513
|
}
|
|
2472
|
-
function RouteGuard({
|
|
2473
|
-
children,
|
|
2474
|
-
builtInAuth = true,
|
|
2475
|
-
paths = {},
|
|
2476
|
-
publicRoutes = [],
|
|
2477
|
-
loadingFallback
|
|
2478
|
-
}) {
|
|
2479
|
-
const { isSignedIn, isLoaded, afterSignInUrl, baseUrl } = useInsforge();
|
|
2480
|
-
const { signIn = "/sign-in", signUp = "/sign-up", forgotPassword = "/forgot-password" } = paths;
|
|
2481
|
-
const [currentPath, setCurrentPath] = useState("");
|
|
2482
|
-
useEffect(() => {
|
|
2483
|
-
const updatePath = () => {
|
|
2484
|
-
const path = window.location.hash ? window.location.hash.slice(1) : window.location.pathname;
|
|
2485
|
-
setCurrentPath(path || "/");
|
|
2486
|
-
};
|
|
2487
|
-
updatePath();
|
|
2488
|
-
window.addEventListener("hashchange", updatePath);
|
|
2489
|
-
window.addEventListener("popstate", updatePath);
|
|
2490
|
-
return () => {
|
|
2491
|
-
window.removeEventListener("hashchange", updatePath);
|
|
2492
|
-
window.removeEventListener("popstate", updatePath);
|
|
2493
|
-
};
|
|
2494
|
-
}, []);
|
|
2495
|
-
const isPublicRoute = publicRoutes.some((route) => {
|
|
2496
|
-
if (route.endsWith("/*")) {
|
|
2497
|
-
const prefix = route.slice(0, -2);
|
|
2498
|
-
return currentPath.startsWith(prefix);
|
|
2499
|
-
}
|
|
2500
|
-
return currentPath === route || currentPath.startsWith(route + "?");
|
|
2501
|
-
});
|
|
2502
|
-
useEffect(() => {
|
|
2503
|
-
if (!isLoaded) return;
|
|
2504
|
-
if (isSignedIn) return;
|
|
2505
|
-
if (!isSignedIn) {
|
|
2506
|
-
if (builtInAuth) {
|
|
2507
|
-
const isSignInPage = currentPath === signIn || currentPath.startsWith(signIn + "?");
|
|
2508
|
-
const isSignUpPage = currentPath === signUp || currentPath.startsWith(signUp + "?");
|
|
2509
|
-
const isForgotPasswordPage = currentPath === forgotPassword || currentPath.startsWith(forgotPassword + "?");
|
|
2510
|
-
if (isSignInPage) {
|
|
2511
|
-
const redirectUrl = new URL(afterSignInUrl, window.location.origin).href;
|
|
2512
|
-
const authUrl = new URL("/auth/sign-in", baseUrl);
|
|
2513
|
-
authUrl.searchParams.set("redirect", redirectUrl);
|
|
2514
|
-
window.location.replace(authUrl.toString());
|
|
2515
|
-
return;
|
|
2516
|
-
}
|
|
2517
|
-
if (isSignUpPage) {
|
|
2518
|
-
const redirectUrl = new URL(afterSignInUrl, window.location.origin).href;
|
|
2519
|
-
const authUrl = new URL("/auth/sign-up", baseUrl);
|
|
2520
|
-
authUrl.searchParams.set("redirect", redirectUrl);
|
|
2521
|
-
window.location.replace(authUrl.toString());
|
|
2522
|
-
return;
|
|
2523
|
-
}
|
|
2524
|
-
if (isForgotPasswordPage) {
|
|
2525
|
-
const authUrl = new URL("/auth/forgot-password", baseUrl);
|
|
2526
|
-
window.location.replace(authUrl.toString());
|
|
2527
|
-
return;
|
|
2528
|
-
}
|
|
2529
|
-
if (isPublicRoute) {
|
|
2530
|
-
return;
|
|
2531
|
-
} else {
|
|
2532
|
-
const redirectUrl = new URL(afterSignInUrl, window.location.origin).href;
|
|
2533
|
-
const authUrl = new URL("/auth/sign-in", baseUrl);
|
|
2534
|
-
authUrl.searchParams.set("redirect", redirectUrl);
|
|
2535
|
-
window.location.replace(authUrl.toString());
|
|
2536
|
-
}
|
|
2537
|
-
} else {
|
|
2538
|
-
if (isPublicRoute) {
|
|
2539
|
-
return;
|
|
2540
|
-
} else {
|
|
2541
|
-
window.location.href = signIn + "?redirect=" + afterSignInUrl;
|
|
2542
|
-
}
|
|
2543
|
-
}
|
|
2544
|
-
}
|
|
2545
|
-
}, [
|
|
2546
|
-
isLoaded,
|
|
2547
|
-
isSignedIn,
|
|
2548
|
-
currentPath,
|
|
2549
|
-
isPublicRoute,
|
|
2550
|
-
builtInAuth,
|
|
2551
|
-
baseUrl,
|
|
2552
|
-
signIn,
|
|
2553
|
-
signUp,
|
|
2554
|
-
forgotPassword,
|
|
2555
|
-
afterSignInUrl
|
|
2556
|
-
]);
|
|
2557
|
-
if (!isLoaded) {
|
|
2558
|
-
return /* @__PURE__ */ jsx(Fragment, { children: loadingFallback });
|
|
2559
|
-
}
|
|
2560
|
-
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
2561
|
-
}
|
|
2562
2514
|
|
|
2563
|
-
export { AuthBranding, AuthContainer, AuthDivider, AuthEmailVerificationStep, AuthErrorBanner, AuthFormField, AuthHeader, AuthLink, AuthOAuthButton, AuthOAuthProviders, AuthPasswordField, AuthPasswordStrengthIndicator, AuthResetPasswordVerificationStep, AuthSubmitButton, AuthVerificationCodeInput, BrowserNavigationAdapter, ForgotPassword, ForgotPasswordForm, InsforgeProvider, NavigationProvider, OAUTH_PROVIDER_CONFIG, Protect, ResetPassword, ResetPasswordForm,
|
|
2515
|
+
export { AuthBranding, AuthContainer, AuthDivider, AuthEmailVerificationStep, AuthErrorBanner, AuthFormField, AuthHeader, AuthLink, AuthOAuthButton, AuthOAuthProviders, AuthPasswordField, AuthPasswordStrengthIndicator, AuthResetPasswordVerificationStep, AuthSubmitButton, AuthVerificationCodeInput, BrowserNavigationAdapter, ForgotPassword, ForgotPasswordForm, InsforgeProvider, NavigationProvider, OAUTH_PROVIDER_CONFIG, Protect, ResetPassword, ResetPasswordForm, SignIn, SignInButton, SignInForm, SignUp, SignUpButton, SignUpForm, SignedIn, SignedOut, UserButton, VerifyEmail, VerifyEmailStatus, checkPasswordStrength, createPasswordSchema, emailSchema, getAllProviderConfigs, getProviderConfig, passwordSchema, resolveAuthPath, resolveAuthUrl, useAuth, useInsforge, useNavigationAdapter, usePublicAuthConfig, useSearchParams, useUser, validateEmail, validatePassword };
|
|
2564
2516
|
//# sourceMappingURL=index.js.map
|
|
2565
2517
|
//# sourceMappingURL=index.js.map
|