@insforge/react 1.1.4 → 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/README.md +718 -718
- 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 +125 -5
- package/dist/components.cjs.map +1 -1
- package/dist/components.js +125 -5
- 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 +149 -6
- 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 +148 -7
- 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/components.cjs
CHANGED
|
@@ -1778,6 +1778,7 @@ function useInsforge() {
|
|
|
1778
1778
|
exchangeResetPasswordToken: () => Promise.resolve({ error: { message: "SSR mode" } }),
|
|
1779
1779
|
loginWithOAuth: () => Promise.resolve(),
|
|
1780
1780
|
getPublicAuthConfig: () => Promise.resolve(null),
|
|
1781
|
+
getSession: () => Promise.resolve(null),
|
|
1781
1782
|
baseUrl: "",
|
|
1782
1783
|
afterSignInUrl: "/"
|
|
1783
1784
|
};
|
|
@@ -3646,8 +3647,36 @@ function SignInForm({
|
|
|
3646
3647
|
] })
|
|
3647
3648
|
] });
|
|
3648
3649
|
}
|
|
3650
|
+
|
|
3651
|
+
// src/lib/hosted-auth.ts
|
|
3652
|
+
function isHostedAuthEnvironment() {
|
|
3653
|
+
if (typeof window === "undefined") {
|
|
3654
|
+
return false;
|
|
3655
|
+
}
|
|
3656
|
+
const { hostname, port, protocol } = window.location;
|
|
3657
|
+
if (hostname === "localhost" && port === "7130") {
|
|
3658
|
+
return true;
|
|
3659
|
+
}
|
|
3660
|
+
if (protocol === "https:" && hostname.endsWith(".insforge.app")) {
|
|
3661
|
+
return true;
|
|
3662
|
+
}
|
|
3663
|
+
return false;
|
|
3664
|
+
}
|
|
3665
|
+
function buildLegacyAuthUrl(redirectUrl, session) {
|
|
3666
|
+
const url = new URL(redirectUrl);
|
|
3667
|
+
url.searchParams.set("access_token", session.accessToken);
|
|
3668
|
+
url.searchParams.set("user_id", session.userId);
|
|
3669
|
+
url.searchParams.set("email", session.email);
|
|
3670
|
+
if (session.name) {
|
|
3671
|
+
url.searchParams.set("name", session.name);
|
|
3672
|
+
}
|
|
3673
|
+
if (session.csrfToken) {
|
|
3674
|
+
url.searchParams.set("csrf_token", session.csrfToken);
|
|
3675
|
+
}
|
|
3676
|
+
return url.toString();
|
|
3677
|
+
}
|
|
3649
3678
|
function SignIn({ onError, ...uiProps }) {
|
|
3650
|
-
const { signIn, verifyEmail, loginWithOAuth } = useInsforge();
|
|
3679
|
+
const { signIn, verifyEmail, loginWithOAuth, isSignedIn, getSession, afterSignInUrl } = useInsforge();
|
|
3651
3680
|
const { authConfig } = usePublicAuthConfig();
|
|
3652
3681
|
const [email, setEmail] = React2.useState("");
|
|
3653
3682
|
const [password, setPassword] = React2.useState("");
|
|
@@ -3657,6 +3686,37 @@ function SignIn({ onError, ...uiProps }) {
|
|
|
3657
3686
|
const [oauthLoading] = React2.useState(null);
|
|
3658
3687
|
const searchParams = useSearchParams();
|
|
3659
3688
|
const redirectUrl = searchParams.get("redirect");
|
|
3689
|
+
const isHandlingOAuthRedirectRef = React2.useRef(false);
|
|
3690
|
+
React2.useEffect(() => {
|
|
3691
|
+
async function handleOAuthComplete() {
|
|
3692
|
+
if (!isSignedIn || isHandlingOAuthRedirectRef.current) return;
|
|
3693
|
+
const isHosted = isHostedAuthEnvironment();
|
|
3694
|
+
if (isHosted && redirectUrl) {
|
|
3695
|
+
isHandlingOAuthRedirectRef.current = true;
|
|
3696
|
+
try {
|
|
3697
|
+
const session = await getSession();
|
|
3698
|
+
if (!session) {
|
|
3699
|
+
isHandlingOAuthRedirectRef.current = false;
|
|
3700
|
+
return;
|
|
3701
|
+
}
|
|
3702
|
+
const legacyUrl = buildLegacyAuthUrl(redirectUrl, {
|
|
3703
|
+
accessToken: session.accessToken,
|
|
3704
|
+
userId: session.user.id,
|
|
3705
|
+
email: session.user.email,
|
|
3706
|
+
name: session.user.profile?.name || ""
|
|
3707
|
+
});
|
|
3708
|
+
window.location.href = legacyUrl;
|
|
3709
|
+
} catch (err) {
|
|
3710
|
+
console.error("Failed to redirect after OAuth:", err);
|
|
3711
|
+
isHandlingOAuthRedirectRef.current = false;
|
|
3712
|
+
}
|
|
3713
|
+
} else if (!isHosted) {
|
|
3714
|
+
const finalUrl = redirectUrl || afterSignInUrl || "/";
|
|
3715
|
+
window.location.href = new URL(finalUrl, window.location.origin).toString();
|
|
3716
|
+
}
|
|
3717
|
+
}
|
|
3718
|
+
void handleOAuthComplete();
|
|
3719
|
+
}, [isSignedIn, redirectUrl, getSession, afterSignInUrl]);
|
|
3660
3720
|
async function handleSubmit(e) {
|
|
3661
3721
|
e.preventDefault();
|
|
3662
3722
|
setLoading(true);
|
|
@@ -3671,9 +3731,16 @@ function SignIn({ onError, ...uiProps }) {
|
|
|
3671
3731
|
}
|
|
3672
3732
|
throw new Error(result.error);
|
|
3673
3733
|
}
|
|
3674
|
-
const { user, redirectTo } = result;
|
|
3734
|
+
const { user, accessToken, redirectTo, csrfToken } = result;
|
|
3675
3735
|
if (user) {
|
|
3676
3736
|
const finalUrl = new URL(redirectTo || redirectUrl || "", window.location.origin);
|
|
3737
|
+
finalUrl.searchParams.set("access_token", accessToken);
|
|
3738
|
+
finalUrl.searchParams.set("user_id", user.id);
|
|
3739
|
+
finalUrl.searchParams.set("email", user.email);
|
|
3740
|
+
finalUrl.searchParams.set("name", user.profile?.name || "");
|
|
3741
|
+
if (csrfToken) {
|
|
3742
|
+
finalUrl.searchParams.set("csrf_token", csrfToken);
|
|
3743
|
+
}
|
|
3677
3744
|
window.location.href = finalUrl.toString();
|
|
3678
3745
|
}
|
|
3679
3746
|
} catch (err) {
|
|
@@ -3694,6 +3761,13 @@ function SignIn({ onError, ...uiProps }) {
|
|
|
3694
3761
|
throw new Error("Verification failed");
|
|
3695
3762
|
}
|
|
3696
3763
|
const finalUrl = new URL(result.redirectTo || redirectUrl || "", window.location.origin);
|
|
3764
|
+
finalUrl.searchParams.set("access_token", result.accessToken);
|
|
3765
|
+
finalUrl.searchParams.set("user_id", result.user.id);
|
|
3766
|
+
finalUrl.searchParams.set("email", result.user.email);
|
|
3767
|
+
finalUrl.searchParams.set("name", result.user.profile?.name || "");
|
|
3768
|
+
if (result.csrfToken) {
|
|
3769
|
+
finalUrl.searchParams.set("csrf_token", result.csrfToken);
|
|
3770
|
+
}
|
|
3697
3771
|
window.location.href = finalUrl.toString();
|
|
3698
3772
|
} catch (err) {
|
|
3699
3773
|
const errorMessage = err instanceof Error ? err.message : "Invalid verification code";
|
|
@@ -3702,7 +3776,7 @@ function SignIn({ onError, ...uiProps }) {
|
|
|
3702
3776
|
}
|
|
3703
3777
|
function handleOAuth(provider) {
|
|
3704
3778
|
try {
|
|
3705
|
-
void loginWithOAuth(provider,
|
|
3779
|
+
void loginWithOAuth(provider, window.location.href);
|
|
3706
3780
|
} catch (err) {
|
|
3707
3781
|
const errorMessage = err instanceof Error ? err.message : "OAuth login failed";
|
|
3708
3782
|
setError(errorMessage);
|
|
@@ -3854,7 +3928,7 @@ function createPasswordSchema(options) {
|
|
|
3854
3928
|
}
|
|
3855
3929
|
createPasswordSchema();
|
|
3856
3930
|
function SignUp({ onError, emailRedirectTo, ...uiProps }) {
|
|
3857
|
-
const { signUp, verifyEmail, loginWithOAuth } = useInsforge();
|
|
3931
|
+
const { signUp, verifyEmail, loginWithOAuth, isSignedIn, getSession, afterSignInUrl } = useInsforge();
|
|
3858
3932
|
const { authConfig } = usePublicAuthConfig();
|
|
3859
3933
|
const [email, setEmail] = React2.useState("");
|
|
3860
3934
|
const [password, setPassword] = React2.useState("");
|
|
@@ -3864,6 +3938,37 @@ function SignUp({ onError, emailRedirectTo, ...uiProps }) {
|
|
|
3864
3938
|
const [oauthLoading] = React2.useState(null);
|
|
3865
3939
|
const searchParams = useSearchParams();
|
|
3866
3940
|
const redirectUrl = searchParams.get("redirect");
|
|
3941
|
+
const isHandlingOAuthRedirectRef = React2.useRef(false);
|
|
3942
|
+
React2.useEffect(() => {
|
|
3943
|
+
async function handleOAuthComplete() {
|
|
3944
|
+
if (!isSignedIn || isHandlingOAuthRedirectRef.current) return;
|
|
3945
|
+
const isHosted = isHostedAuthEnvironment();
|
|
3946
|
+
if (isHosted && redirectUrl) {
|
|
3947
|
+
isHandlingOAuthRedirectRef.current = true;
|
|
3948
|
+
try {
|
|
3949
|
+
const session = await getSession();
|
|
3950
|
+
if (!session) {
|
|
3951
|
+
isHandlingOAuthRedirectRef.current = false;
|
|
3952
|
+
return;
|
|
3953
|
+
}
|
|
3954
|
+
const legacyUrl = buildLegacyAuthUrl(redirectUrl, {
|
|
3955
|
+
accessToken: session.accessToken,
|
|
3956
|
+
userId: session.user.id,
|
|
3957
|
+
email: session.user.email,
|
|
3958
|
+
name: session.user.profile?.name || ""
|
|
3959
|
+
});
|
|
3960
|
+
window.location.href = legacyUrl;
|
|
3961
|
+
} catch (err) {
|
|
3962
|
+
console.error("Failed to redirect after OAuth:", err);
|
|
3963
|
+
isHandlingOAuthRedirectRef.current = false;
|
|
3964
|
+
}
|
|
3965
|
+
} else if (!isHosted) {
|
|
3966
|
+
const finalUrl = redirectUrl || afterSignInUrl || "/";
|
|
3967
|
+
window.location.href = new URL(finalUrl, window.location.origin).toString();
|
|
3968
|
+
}
|
|
3969
|
+
}
|
|
3970
|
+
void handleOAuthComplete();
|
|
3971
|
+
}, [isSignedIn, redirectUrl, getSession, afterSignInUrl]);
|
|
3867
3972
|
async function handleSubmit(e) {
|
|
3868
3973
|
e.preventDefault();
|
|
3869
3974
|
setLoading(true);
|
|
@@ -3905,7 +4010,15 @@ function SignUp({ onError, emailRedirectTo, ...uiProps }) {
|
|
|
3905
4010
|
return;
|
|
3906
4011
|
}
|
|
3907
4012
|
if (result.accessToken && result.user) {
|
|
4013
|
+
const csrfToken = result.csrfToken;
|
|
3908
4014
|
const finalUrl = new URL(result.redirectTo || redirectUrl || "", window.location.origin);
|
|
4015
|
+
finalUrl.searchParams.set("access_token", result.accessToken);
|
|
4016
|
+
finalUrl.searchParams.set("user_id", result.user.id);
|
|
4017
|
+
finalUrl.searchParams.set("email", result.user.email);
|
|
4018
|
+
finalUrl.searchParams.set("name", result.user.profile?.name || "");
|
|
4019
|
+
if (csrfToken) {
|
|
4020
|
+
finalUrl.searchParams.set("csrf_token", csrfToken);
|
|
4021
|
+
}
|
|
3909
4022
|
window.location.href = finalUrl.toString();
|
|
3910
4023
|
}
|
|
3911
4024
|
} catch (err) {
|
|
@@ -3926,6 +4039,13 @@ function SignUp({ onError, emailRedirectTo, ...uiProps }) {
|
|
|
3926
4039
|
throw new Error("Verification failed");
|
|
3927
4040
|
}
|
|
3928
4041
|
const finalUrl = new URL(result.redirectTo || redirectUrl || "", window.location.origin);
|
|
4042
|
+
finalUrl.searchParams.set("access_token", result.accessToken);
|
|
4043
|
+
finalUrl.searchParams.set("user_id", result.user.id);
|
|
4044
|
+
finalUrl.searchParams.set("email", result.user.email);
|
|
4045
|
+
finalUrl.searchParams.set("name", result.user.profile?.name || "");
|
|
4046
|
+
if (result.csrfToken) {
|
|
4047
|
+
finalUrl.searchParams.set("csrf_token", result.csrfToken);
|
|
4048
|
+
}
|
|
3929
4049
|
window.location.href = finalUrl.toString();
|
|
3930
4050
|
} catch (err) {
|
|
3931
4051
|
const errorMessage = err instanceof Error ? err.message : "Invalid verification code";
|
|
@@ -3934,7 +4054,7 @@ function SignUp({ onError, emailRedirectTo, ...uiProps }) {
|
|
|
3934
4054
|
}
|
|
3935
4055
|
function handleOAuth(provider) {
|
|
3936
4056
|
try {
|
|
3937
|
-
void loginWithOAuth(provider,
|
|
4057
|
+
void loginWithOAuth(provider, window.location.href);
|
|
3938
4058
|
} catch (err) {
|
|
3939
4059
|
const errorMessage = err instanceof Error ? err.message : "OAuth login failed";
|
|
3940
4060
|
setError(errorMessage);
|