@insforge/react 1.1.1 → 1.1.2-dev.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/atoms.cjs.map +1 -1
- package/dist/atoms.d.cts +5 -3
- package/dist/atoms.d.ts +5 -3
- package/dist/atoms.js.map +1 -1
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +1 -1
- package/dist/components.d.ts +1 -1
- 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 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -2
- package/dist/index.d.ts +11 -2
- package/dist/index.js +45 -37
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export { ConditionalProps, ForgotPassword, ForgotPasswordProps, Protect, ProtectProps, ResetPassword, ResetPasswordProps, SignIn, SignInButton, SignInButtonProps, SignInProps, SignOutButton, SignOutButtonProps, SignUp, SignUpButton, SignUpButtonProps, SignUpProps, SignedIn, SignedOut, UserButton, UserButtonProps, UserProfileModal, UserProfileModalProps, VerifyEmail, VerifyEmailProps } from './components.cjs';
|
|
2
2
|
export { ForgotPasswordForm, ForgotPasswordFormProps, ResetPasswordForm, ResetPasswordFormProps, SignInForm, SignInFormProps, SignUpForm, SignUpFormProps, VerifyEmailStatus, VerifyEmailStatusProps } from './forms.cjs';
|
|
3
|
-
export { AuthBranding, AuthContainer, AuthContainerProps, AuthDivider, AuthDividerProps, AuthEmailVerificationStep,
|
|
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';
|
|
5
5
|
import { ReactNode } from 'react';
|
|
6
6
|
import { InsforgeUser, InsforgeContextValue, OAuthProvider } from '@insforge/shared';
|
|
7
|
-
export { InsforgeContextValue, InsforgeUser, OAuthProvider } from '@insforge/shared';
|
|
7
|
+
export { InsforgeAuthConfig, InsforgeAuthMethods, InsforgeAuthState, InsforgeContextValue, InsforgeUser, OAuthProvider } from '@insforge/shared';
|
|
8
8
|
import { InsForgeClient } from '@insforge/sdk';
|
|
9
9
|
export { useAuth, usePublicAuthConfig, useUser } from './hooks.cjs';
|
|
10
10
|
export { checkPasswordStrength, createPasswordSchema, emailSchema, passwordSchema, resolveAuthPath, resolveAuthUrl, validateEmail, validatePassword } from './lib.cjs';
|
|
@@ -51,6 +51,15 @@ interface InsforgeProviderProps {
|
|
|
51
51
|
* Uses singleton InsforgeManager to manage state across packages.
|
|
52
52
|
* Context only subscribes to Manager and triggers React re-renders.
|
|
53
53
|
*
|
|
54
|
+
* Architecture (pattern learned from Clerk):
|
|
55
|
+
* - InsforgeMethodsContext: Stable method references (NEVER change)
|
|
56
|
+
* - InsforgeAuthStateContext: Reactive auth state (changes on sign in/out)
|
|
57
|
+
* - InsforgeConfigContext: Static configuration values
|
|
58
|
+
* - InsforgeContext: Combined context for backward compatibility
|
|
59
|
+
*
|
|
60
|
+
* This architecture prevents useEffect re-runs when auth state changes,
|
|
61
|
+
* solving the "duplicate request" bug in components like VerifyEmail.
|
|
62
|
+
*
|
|
54
63
|
* @example
|
|
55
64
|
* ```tsx
|
|
56
65
|
* // Basic usage (React/Vite)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export { ConditionalProps, ForgotPassword, ForgotPasswordProps, Protect, ProtectProps, ResetPassword, ResetPasswordProps, SignIn, SignInButton, SignInButtonProps, SignInProps, SignOutButton, SignOutButtonProps, SignUp, SignUpButton, SignUpButtonProps, SignUpProps, SignedIn, SignedOut, UserButton, UserButtonProps, UserProfileModal, UserProfileModalProps, VerifyEmail, VerifyEmailProps } from './components.js';
|
|
2
2
|
export { ForgotPasswordForm, ForgotPasswordFormProps, ResetPasswordForm, ResetPasswordFormProps, SignInForm, SignInFormProps, SignUpForm, SignUpFormProps, VerifyEmailStatus, VerifyEmailStatusProps } from './forms.js';
|
|
3
|
-
export { AuthBranding, AuthContainer, AuthContainerProps, AuthDivider, AuthDividerProps, AuthEmailVerificationStep,
|
|
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';
|
|
5
5
|
import { ReactNode } from 'react';
|
|
6
6
|
import { InsforgeUser, InsforgeContextValue, OAuthProvider } from '@insforge/shared';
|
|
7
|
-
export { InsforgeContextValue, InsforgeUser, OAuthProvider } from '@insforge/shared';
|
|
7
|
+
export { InsforgeAuthConfig, InsforgeAuthMethods, InsforgeAuthState, InsforgeContextValue, InsforgeUser, OAuthProvider } from '@insforge/shared';
|
|
8
8
|
import { InsForgeClient } from '@insforge/sdk';
|
|
9
9
|
export { useAuth, usePublicAuthConfig, useUser } from './hooks.js';
|
|
10
10
|
export { checkPasswordStrength, createPasswordSchema, emailSchema, passwordSchema, resolveAuthPath, resolveAuthUrl, validateEmail, validatePassword } from './lib.js';
|
|
@@ -51,6 +51,15 @@ interface InsforgeProviderProps {
|
|
|
51
51
|
* Uses singleton InsforgeManager to manage state across packages.
|
|
52
52
|
* Context only subscribes to Manager and triggers React re-renders.
|
|
53
53
|
*
|
|
54
|
+
* Architecture (pattern learned from Clerk):
|
|
55
|
+
* - InsforgeMethodsContext: Stable method references (NEVER change)
|
|
56
|
+
* - InsforgeAuthStateContext: Reactive auth state (changes on sign in/out)
|
|
57
|
+
* - InsforgeConfigContext: Static configuration values
|
|
58
|
+
* - InsforgeContext: Combined context for backward compatibility
|
|
59
|
+
*
|
|
60
|
+
* This architecture prevents useEffect re-runs when auth state changes,
|
|
61
|
+
* solving the "duplicate request" bug in components like VerifyEmail.
|
|
62
|
+
*
|
|
54
63
|
* @example
|
|
55
64
|
* ```tsx
|
|
56
65
|
* // Basic usage (React/Vite)
|
package/dist/index.js
CHANGED
|
@@ -15,7 +15,7 @@ if (typeof document !== 'undefined' && typeof window !== 'undefined') {
|
|
|
15
15
|
import * as React2 from 'react';
|
|
16
16
|
import { createContext, forwardRef, useContext, useState, useMemo, useEffect, useRef, useCallback, isValidElement, cloneElement } from 'react';
|
|
17
17
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
18
|
-
import { InsforgeContext } from '@insforge/shared/react';
|
|
18
|
+
import { InsforgeMethodsContext, InsforgeConfigContext, InsforgeAuthStateContext, InsforgeContext } from '@insforge/shared/react';
|
|
19
19
|
import { AlertTriangle, Check, EyeOff, Eye, Loader2, CircleCheck, X, User, LogOut } from 'lucide-react';
|
|
20
20
|
import { z } from 'zod';
|
|
21
21
|
import { createPortal } from 'react-dom';
|
|
@@ -545,8 +545,8 @@ var InsforgeManager = class _InsforgeManager {
|
|
|
545
545
|
this.listeners.forEach((listener) => listener(state));
|
|
546
546
|
}
|
|
547
547
|
// Load auth state
|
|
548
|
-
//
|
|
549
|
-
// Called after hydration to
|
|
548
|
+
// Gets session and user data from getCurrentSession()
|
|
549
|
+
// Called after hydration to restore authentication state
|
|
550
550
|
async loadAuthState() {
|
|
551
551
|
try {
|
|
552
552
|
const {
|
|
@@ -570,30 +570,18 @@ var InsforgeManager = class _InsforgeManager {
|
|
|
570
570
|
}
|
|
571
571
|
}
|
|
572
572
|
}
|
|
573
|
-
const
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
this.
|
|
581
|
-
if (this.config.onAuthChange) {
|
|
582
|
-
this.config.onAuthChange(userData);
|
|
583
|
-
}
|
|
584
|
-
this.isLoaded = true;
|
|
585
|
-
this.notifyListeners();
|
|
586
|
-
return { success: true };
|
|
587
|
-
} else {
|
|
588
|
-
this.user = null;
|
|
589
|
-
if (this.config.onAuthChange) {
|
|
590
|
-
this.config.onAuthChange(null);
|
|
591
|
-
}
|
|
592
|
-
this.isLoaded = true;
|
|
593
|
-
this.notifyListeners();
|
|
594
|
-
const errorMessage = userResult.error?.message ?? "failed_to_get_user";
|
|
595
|
-
return { success: false, error: errorMessage };
|
|
573
|
+
const userData = {
|
|
574
|
+
id: session.user.id,
|
|
575
|
+
email: session.user.email,
|
|
576
|
+
profile: session.user.profile
|
|
577
|
+
};
|
|
578
|
+
this.user = userData;
|
|
579
|
+
if (this.config.onAuthChange) {
|
|
580
|
+
this.config.onAuthChange(userData);
|
|
596
581
|
}
|
|
582
|
+
this.isLoaded = true;
|
|
583
|
+
this.notifyListeners();
|
|
584
|
+
return { success: true };
|
|
597
585
|
} catch (error) {
|
|
598
586
|
this.user = null;
|
|
599
587
|
if (this.config.onAuthChange) {
|
|
@@ -2191,14 +2179,8 @@ function InsforgeProviderCore({
|
|
|
2191
2179
|
unsubscribe();
|
|
2192
2180
|
};
|
|
2193
2181
|
}, [manager]);
|
|
2194
|
-
const
|
|
2182
|
+
const stableMethods = useMemo(
|
|
2195
2183
|
() => ({
|
|
2196
|
-
// State from Manager
|
|
2197
|
-
user: state.user,
|
|
2198
|
-
userId: state.userId,
|
|
2199
|
-
isLoaded: state.isLoaded,
|
|
2200
|
-
isSignedIn: state.isSignedIn,
|
|
2201
|
-
// Methods delegated to Manager
|
|
2202
2184
|
setUser: (user) => manager.setUser(user),
|
|
2203
2185
|
signIn: (email, password) => manager.signIn(email, password),
|
|
2204
2186
|
signUp: (email, password) => manager.signUp(email, password),
|
|
@@ -2211,14 +2193,40 @@ function InsforgeProviderCore({
|
|
|
2211
2193
|
verifyEmail: (otp, email) => manager.verifyEmail(otp, email),
|
|
2212
2194
|
exchangeResetPasswordToken: (email, code) => manager.exchangeResetPasswordToken(email, code),
|
|
2213
2195
|
loginWithOAuth: (provider, redirectTo) => manager.loginWithOAuth(provider, redirectTo),
|
|
2214
|
-
getPublicAuthConfig: () => manager.getPublicAuthConfig()
|
|
2215
|
-
|
|
2196
|
+
getPublicAuthConfig: () => manager.getPublicAuthConfig()
|
|
2197
|
+
}),
|
|
2198
|
+
[manager]
|
|
2199
|
+
// Only depends on manager (stable)
|
|
2200
|
+
);
|
|
2201
|
+
const stableConfig = useMemo(
|
|
2202
|
+
() => ({
|
|
2216
2203
|
baseUrl: manager.getConfig().client.getHttpClient().baseUrl,
|
|
2217
2204
|
afterSignInUrl: manager.getConfig().afterSignInUrl || "/"
|
|
2218
2205
|
}),
|
|
2219
|
-
[
|
|
2206
|
+
[manager]
|
|
2207
|
+
// Only depends on manager (stable)
|
|
2208
|
+
);
|
|
2209
|
+
const authState = useMemo(
|
|
2210
|
+
() => ({
|
|
2211
|
+
user: state.user,
|
|
2212
|
+
userId: state.userId,
|
|
2213
|
+
isLoaded: state.isLoaded,
|
|
2214
|
+
isSignedIn: state.isSignedIn
|
|
2215
|
+
}),
|
|
2216
|
+
[state.user, state.userId, state.isLoaded, state.isSignedIn]
|
|
2217
|
+
);
|
|
2218
|
+
const contextValue = useMemo(
|
|
2219
|
+
() => ({
|
|
2220
|
+
// Reactive state
|
|
2221
|
+
...authState,
|
|
2222
|
+
// Stable methods (references don't change!)
|
|
2223
|
+
...stableMethods,
|
|
2224
|
+
// Stable config
|
|
2225
|
+
...stableConfig
|
|
2226
|
+
}),
|
|
2227
|
+
[authState, stableMethods, stableConfig]
|
|
2220
2228
|
);
|
|
2221
|
-
return /* @__PURE__ */ jsx(InsforgeContext.Provider, { value: contextValue, children });
|
|
2229
|
+
return /* @__PURE__ */ jsx(InsforgeMethodsContext.Provider, { value: stableMethods, children: /* @__PURE__ */ jsx(InsforgeConfigContext.Provider, { value: stableConfig, children: /* @__PURE__ */ jsx(InsforgeAuthStateContext.Provider, { value: authState, children: /* @__PURE__ */ jsx(InsforgeContext.Provider, { value: contextValue, children }) }) }) });
|
|
2222
2230
|
}
|
|
2223
2231
|
function InsforgeProvider(props) {
|
|
2224
2232
|
return /* @__PURE__ */ jsx(StyleProvider, { children: /* @__PURE__ */ jsx(NavigationProvider, { adapter: BrowserNavigationAdapter, children: /* @__PURE__ */ jsx(InsforgeProviderCore, { ...props }) }) });
|