@insforge/react 1.1.5 → 1.1.6-test.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 +1 -0
- package/dist/atoms.cjs.map +1 -1
- package/dist/atoms.js +1 -0
- package/dist/atoms.js.map +1 -1
- package/dist/components.cjs +95 -4
- package/dist/components.cjs.map +1 -1
- package/dist/components.js +95 -4
- package/dist/components.js.map +1 -1
- package/dist/forms.cjs +1 -0
- package/dist/forms.cjs.map +1 -1
- package/dist/forms.js +1 -0
- package/dist/forms.js.map +1 -1
- package/dist/hooks.cjs +1 -0
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.js +1 -0
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +119 -5
- 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 +118 -6
- package/dist/index.js.map +1 -1
- package/dist/lib.cjs +30 -0
- package/dist/lib.cjs.map +1 -1
- package/dist/lib.d.cts +39 -1
- package/dist/lib.d.ts +39 -1
- package/dist/lib.js +29 -1
- package/dist/lib.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -7,7 +7,7 @@ import { InsforgeUser, InsforgeContextValue, OAuthProvider } from '@insforge/sha
|
|
|
7
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
|
-
export { checkPasswordStrength, createPasswordSchema, emailSchema, passwordSchema, resolveAuthPath, resolveAuthUrl, validateEmail, validatePassword } from './lib.cjs';
|
|
10
|
+
export { LegacyAuthSession, buildLegacyAuthUrl, checkPasswordStrength, createPasswordSchema, emailSchema, isHostedAuthEnvironment, passwordSchema, resolveAuthPath, resolveAuthUrl, validateEmail, validatePassword } from './lib.cjs';
|
|
11
11
|
import { OAuthProviderConfig } from './types.cjs';
|
|
12
12
|
export { AuthConfig, EmailVerificationMethod } from './types.cjs';
|
|
13
13
|
export { BrowserNavigationAdapter, NavigationAdapter, NavigationProvider, NavigationProviderProps, useNavigationAdapter, useSearchParams } from './navigation.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { InsforgeUser, InsforgeContextValue, OAuthProvider } from '@insforge/sha
|
|
|
7
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
|
-
export { checkPasswordStrength, createPasswordSchema, emailSchema, passwordSchema, resolveAuthPath, resolveAuthUrl, validateEmail, validatePassword } from './lib.js';
|
|
10
|
+
export { LegacyAuthSession, buildLegacyAuthUrl, checkPasswordStrength, createPasswordSchema, emailSchema, isHostedAuthEnvironment, passwordSchema, resolveAuthPath, resolveAuthUrl, validateEmail, validatePassword } from './lib.js';
|
|
11
11
|
import { OAuthProviderConfig } from './types.js';
|
|
12
12
|
export { AuthConfig, EmailVerificationMethod } from './types.js';
|
|
13
13
|
export { BrowserNavigationAdapter, NavigationAdapter, NavigationProvider, NavigationProviderProps, useNavigationAdapter, useSearchParams } from './navigation.js';
|
package/dist/index.js
CHANGED
|
@@ -821,6 +821,26 @@ var InsforgeManager = class _InsforgeManager {
|
|
|
821
821
|
getSDK() {
|
|
822
822
|
return this.sdk;
|
|
823
823
|
}
|
|
824
|
+
/**
|
|
825
|
+
* Get current session with accessToken
|
|
826
|
+
* Used for hosted auth to construct legacy flow redirect URL
|
|
827
|
+
*
|
|
828
|
+
* @returns Session with accessToken and user, or null if not signed in
|
|
829
|
+
*/
|
|
830
|
+
async getSession() {
|
|
831
|
+
const result = await this.sdk.auth.getCurrentSession();
|
|
832
|
+
if (result.data?.session) {
|
|
833
|
+
return {
|
|
834
|
+
accessToken: result.data.session.accessToken,
|
|
835
|
+
user: {
|
|
836
|
+
id: result.data.session.user.id,
|
|
837
|
+
email: result.data.session.user.email,
|
|
838
|
+
profile: result.data.session.user.profile
|
|
839
|
+
}
|
|
840
|
+
};
|
|
841
|
+
}
|
|
842
|
+
return null;
|
|
843
|
+
}
|
|
824
844
|
// Cleanup
|
|
825
845
|
cleanup() {
|
|
826
846
|
if (this.refreshIntervalRef) {
|
|
@@ -2200,7 +2220,8 @@ function InsforgeProviderCore({
|
|
|
2200
2220
|
verifyEmail: (otp, email) => manager.verifyEmail(otp, email),
|
|
2201
2221
|
exchangeResetPasswordToken: (email, code) => manager.exchangeResetPasswordToken(email, code),
|
|
2202
2222
|
loginWithOAuth: (provider, redirectTo) => manager.loginWithOAuth(provider, redirectTo),
|
|
2203
|
-
getPublicAuthConfig: () => manager.getPublicAuthConfig()
|
|
2223
|
+
getPublicAuthConfig: () => manager.getPublicAuthConfig(),
|
|
2224
|
+
getSession: () => manager.getSession()
|
|
2204
2225
|
}),
|
|
2205
2226
|
[manager]
|
|
2206
2227
|
// Only depends on manager (stable)
|
|
@@ -2260,6 +2281,7 @@ function useInsforge() {
|
|
|
2260
2281
|
exchangeResetPasswordToken: () => Promise.resolve({ error: { message: "SSR mode" } }),
|
|
2261
2282
|
loginWithOAuth: () => Promise.resolve(),
|
|
2262
2283
|
getPublicAuthConfig: () => Promise.resolve(null),
|
|
2284
|
+
getSession: () => Promise.resolve(null),
|
|
2263
2285
|
baseUrl: "",
|
|
2264
2286
|
afterSignInUrl: "/"
|
|
2265
2287
|
};
|
|
@@ -4140,8 +4162,36 @@ function SignInForm({
|
|
|
4140
4162
|
] })
|
|
4141
4163
|
] });
|
|
4142
4164
|
}
|
|
4165
|
+
|
|
4166
|
+
// src/lib/hosted-auth.ts
|
|
4167
|
+
function isHostedAuthEnvironment() {
|
|
4168
|
+
if (typeof window === "undefined") {
|
|
4169
|
+
return false;
|
|
4170
|
+
}
|
|
4171
|
+
const { hostname, port, protocol } = window.location;
|
|
4172
|
+
if (hostname === "localhost" && port === "7130") {
|
|
4173
|
+
return true;
|
|
4174
|
+
}
|
|
4175
|
+
if (protocol === "https:" && hostname.endsWith(".insforge.app")) {
|
|
4176
|
+
return true;
|
|
4177
|
+
}
|
|
4178
|
+
return false;
|
|
4179
|
+
}
|
|
4180
|
+
function buildLegacyAuthUrl(redirectUrl, session) {
|
|
4181
|
+
const url = new URL(redirectUrl);
|
|
4182
|
+
url.searchParams.set("access_token", session.accessToken);
|
|
4183
|
+
url.searchParams.set("user_id", session.userId);
|
|
4184
|
+
url.searchParams.set("email", session.email);
|
|
4185
|
+
if (session.name) {
|
|
4186
|
+
url.searchParams.set("name", session.name);
|
|
4187
|
+
}
|
|
4188
|
+
if (session.csrfToken) {
|
|
4189
|
+
url.searchParams.set("csrf_token", session.csrfToken);
|
|
4190
|
+
}
|
|
4191
|
+
return url.toString();
|
|
4192
|
+
}
|
|
4143
4193
|
function SignIn({ onError, ...uiProps }) {
|
|
4144
|
-
const { signIn, verifyEmail, loginWithOAuth } = useInsforge();
|
|
4194
|
+
const { signIn, verifyEmail, loginWithOAuth, isSignedIn, getSession, afterSignInUrl } = useInsforge();
|
|
4145
4195
|
const { authConfig } = usePublicAuthConfig();
|
|
4146
4196
|
const [email, setEmail] = useState("");
|
|
4147
4197
|
const [password, setPassword] = useState("");
|
|
@@ -4151,6 +4201,37 @@ function SignIn({ onError, ...uiProps }) {
|
|
|
4151
4201
|
const [oauthLoading] = useState(null);
|
|
4152
4202
|
const searchParams = useSearchParams();
|
|
4153
4203
|
const redirectUrl = searchParams.get("redirect");
|
|
4204
|
+
const isHandlingOAuthRedirectRef = useRef(false);
|
|
4205
|
+
useEffect(() => {
|
|
4206
|
+
async function handleOAuthComplete() {
|
|
4207
|
+
if (!isSignedIn || isHandlingOAuthRedirectRef.current) return;
|
|
4208
|
+
const isHosted = isHostedAuthEnvironment();
|
|
4209
|
+
if (isHosted && redirectUrl) {
|
|
4210
|
+
isHandlingOAuthRedirectRef.current = true;
|
|
4211
|
+
try {
|
|
4212
|
+
const session = await getSession();
|
|
4213
|
+
if (!session) {
|
|
4214
|
+
isHandlingOAuthRedirectRef.current = false;
|
|
4215
|
+
return;
|
|
4216
|
+
}
|
|
4217
|
+
const legacyUrl = buildLegacyAuthUrl(redirectUrl, {
|
|
4218
|
+
accessToken: session.accessToken,
|
|
4219
|
+
userId: session.user.id,
|
|
4220
|
+
email: session.user.email,
|
|
4221
|
+
name: session.user.profile?.name || ""
|
|
4222
|
+
});
|
|
4223
|
+
window.location.href = legacyUrl;
|
|
4224
|
+
} catch (err) {
|
|
4225
|
+
console.error("Failed to redirect after OAuth:", err);
|
|
4226
|
+
isHandlingOAuthRedirectRef.current = false;
|
|
4227
|
+
}
|
|
4228
|
+
} else if (!isHosted) {
|
|
4229
|
+
const finalUrl = redirectUrl || afterSignInUrl || "/";
|
|
4230
|
+
window.location.href = new URL(finalUrl, window.location.origin).toString();
|
|
4231
|
+
}
|
|
4232
|
+
}
|
|
4233
|
+
void handleOAuthComplete();
|
|
4234
|
+
}, [isSignedIn, redirectUrl, getSession, afterSignInUrl]);
|
|
4154
4235
|
async function handleSubmit(e) {
|
|
4155
4236
|
e.preventDefault();
|
|
4156
4237
|
setLoading(true);
|
|
@@ -4210,7 +4291,7 @@ function SignIn({ onError, ...uiProps }) {
|
|
|
4210
4291
|
}
|
|
4211
4292
|
function handleOAuth(provider) {
|
|
4212
4293
|
try {
|
|
4213
|
-
void loginWithOAuth(provider,
|
|
4294
|
+
void loginWithOAuth(provider, window.location.href);
|
|
4214
4295
|
} catch (err) {
|
|
4215
4296
|
const errorMessage = err instanceof Error ? err.message : "OAuth login failed";
|
|
4216
4297
|
setError(errorMessage);
|
|
@@ -4405,7 +4486,7 @@ function checkPasswordStrength(password) {
|
|
|
4405
4486
|
return { score, feedback };
|
|
4406
4487
|
}
|
|
4407
4488
|
function SignUp({ onError, emailRedirectTo, ...uiProps }) {
|
|
4408
|
-
const { signUp, verifyEmail, loginWithOAuth } = useInsforge();
|
|
4489
|
+
const { signUp, verifyEmail, loginWithOAuth, isSignedIn, getSession, afterSignInUrl } = useInsforge();
|
|
4409
4490
|
const { authConfig } = usePublicAuthConfig();
|
|
4410
4491
|
const [email, setEmail] = useState("");
|
|
4411
4492
|
const [password, setPassword] = useState("");
|
|
@@ -4415,6 +4496,37 @@ function SignUp({ onError, emailRedirectTo, ...uiProps }) {
|
|
|
4415
4496
|
const [oauthLoading] = useState(null);
|
|
4416
4497
|
const searchParams = useSearchParams();
|
|
4417
4498
|
const redirectUrl = searchParams.get("redirect");
|
|
4499
|
+
const isHandlingOAuthRedirectRef = useRef(false);
|
|
4500
|
+
useEffect(() => {
|
|
4501
|
+
async function handleOAuthComplete() {
|
|
4502
|
+
if (!isSignedIn || isHandlingOAuthRedirectRef.current) return;
|
|
4503
|
+
const isHosted = isHostedAuthEnvironment();
|
|
4504
|
+
if (isHosted && redirectUrl) {
|
|
4505
|
+
isHandlingOAuthRedirectRef.current = true;
|
|
4506
|
+
try {
|
|
4507
|
+
const session = await getSession();
|
|
4508
|
+
if (!session) {
|
|
4509
|
+
isHandlingOAuthRedirectRef.current = false;
|
|
4510
|
+
return;
|
|
4511
|
+
}
|
|
4512
|
+
const legacyUrl = buildLegacyAuthUrl(redirectUrl, {
|
|
4513
|
+
accessToken: session.accessToken,
|
|
4514
|
+
userId: session.user.id,
|
|
4515
|
+
email: session.user.email,
|
|
4516
|
+
name: session.user.profile?.name || ""
|
|
4517
|
+
});
|
|
4518
|
+
window.location.href = legacyUrl;
|
|
4519
|
+
} catch (err) {
|
|
4520
|
+
console.error("Failed to redirect after OAuth:", err);
|
|
4521
|
+
isHandlingOAuthRedirectRef.current = false;
|
|
4522
|
+
}
|
|
4523
|
+
} else if (!isHosted) {
|
|
4524
|
+
const finalUrl = redirectUrl || afterSignInUrl || "/";
|
|
4525
|
+
window.location.href = new URL(finalUrl, window.location.origin).toString();
|
|
4526
|
+
}
|
|
4527
|
+
}
|
|
4528
|
+
void handleOAuthComplete();
|
|
4529
|
+
}, [isSignedIn, redirectUrl, getSession, afterSignInUrl]);
|
|
4418
4530
|
async function handleSubmit(e) {
|
|
4419
4531
|
e.preventDefault();
|
|
4420
4532
|
setLoading(true);
|
|
@@ -4500,7 +4612,7 @@ function SignUp({ onError, emailRedirectTo, ...uiProps }) {
|
|
|
4500
4612
|
}
|
|
4501
4613
|
function handleOAuth(provider) {
|
|
4502
4614
|
try {
|
|
4503
|
-
void loginWithOAuth(provider,
|
|
4615
|
+
void loginWithOAuth(provider, window.location.href);
|
|
4504
4616
|
} catch (err) {
|
|
4505
4617
|
const errorMessage = err instanceof Error ? err.message : "OAuth login failed";
|
|
4506
4618
|
setError(errorMessage);
|
|
@@ -5809,6 +5921,6 @@ react-is/cjs/react-is.development.js:
|
|
|
5809
5921
|
*)
|
|
5810
5922
|
*/
|
|
5811
5923
|
|
|
5812
|
-
export { AuthBranding, AuthContainer, AuthDivider, AuthEmailVerificationStep, AuthErrorBanner, AuthFormField, AuthHeader, AuthLink, AuthOAuthButton, AuthOAuthProviders, AuthPasswordField, AuthPasswordStrengthIndicator, AuthResetPasswordVerificationStep, AuthSubmitButton, AuthVerificationCodeInput, BrowserNavigationAdapter, ForgotPassword, ForgotPasswordForm, InsforgeProvider, InsforgeProviderCore, NavigationProvider, OAUTH_PROVIDER_CONFIG, Protect, ResetPassword, ResetPasswordForm, SignIn, SignInButton, SignInForm, SignOutButton, SignUp, SignUpButton, SignUpForm, SignedIn, SignedOut, StyleProvider, UserButton, UserProfileModal, VerifyEmail, VerifyEmailStatus, checkPasswordStrength, createPasswordSchema, emailSchema, getAllProviderConfigs, getProviderConfig, passwordSchema, resolveAuthPath, resolveAuthUrl, theme, useAuth, useInsforge, useNavigationAdapter, usePublicAuthConfig, useSearchParams, useUser, validateEmail, validatePassword };
|
|
5924
|
+
export { AuthBranding, AuthContainer, AuthDivider, AuthEmailVerificationStep, AuthErrorBanner, AuthFormField, AuthHeader, AuthLink, AuthOAuthButton, AuthOAuthProviders, AuthPasswordField, AuthPasswordStrengthIndicator, AuthResetPasswordVerificationStep, AuthSubmitButton, AuthVerificationCodeInput, BrowserNavigationAdapter, ForgotPassword, ForgotPasswordForm, InsforgeProvider, InsforgeProviderCore, NavigationProvider, OAUTH_PROVIDER_CONFIG, Protect, ResetPassword, ResetPasswordForm, SignIn, SignInButton, SignInForm, SignOutButton, SignUp, SignUpButton, SignUpForm, SignedIn, SignedOut, StyleProvider, UserButton, UserProfileModal, VerifyEmail, VerifyEmailStatus, buildLegacyAuthUrl, checkPasswordStrength, createPasswordSchema, emailSchema, getAllProviderConfigs, getProviderConfig, isHostedAuthEnvironment, passwordSchema, resolveAuthPath, resolveAuthUrl, theme, useAuth, useInsforge, useNavigationAdapter, usePublicAuthConfig, useSearchParams, useUser, validateEmail, validatePassword };
|
|
5813
5925
|
//# sourceMappingURL=index.js.map
|
|
5814
5926
|
//# sourceMappingURL=index.js.map
|