@insforge/react 1.0.6 → 1.0.9-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 +1 -1
- package/dist/atoms.cjs.map +1 -1
- package/dist/atoms.js +1 -1
- package/dist/atoms.js.map +1 -1
- package/dist/components.cjs +18 -43
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +5 -4
- package/dist/components.d.ts +5 -4
- package/dist/components.js +18 -43
- package/dist/components.js.map +1 -1
- package/dist/forms.cjs +1 -1
- package/dist/forms.cjs.map +1 -1
- package/dist/forms.js +1 -1
- package/dist/forms.js.map +1 -1
- package/dist/hooks.cjs +1 -1
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +4 -5
- package/dist/hooks.d.ts +4 -5
- package/dist/hooks.js +1 -1
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +41 -93
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +41 -93
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -36,9 +36,9 @@ interface InsforgeProviderProps {
|
|
|
36
36
|
*/
|
|
37
37
|
afterSignInUrl?: string;
|
|
38
38
|
onAuthChange?: (user: InsforgeUser | null) => void;
|
|
39
|
-
onSignIn?: (authToken: string) => Promise<void>;
|
|
39
|
+
onSignIn?: (authToken: string, user: InsforgeUser) => Promise<void>;
|
|
40
40
|
onSignOut?: () => Promise<void>;
|
|
41
|
-
onRefresh?: (authToken: string) => Promise<void>;
|
|
41
|
+
onRefresh?: (authToken: string, user: InsforgeUser) => Promise<void>;
|
|
42
42
|
/**
|
|
43
43
|
* Initial auth state from server (for SSR hydration)
|
|
44
44
|
* @internal - Not intended for public use, used by Next.js package
|
package/dist/index.d.ts
CHANGED
|
@@ -36,9 +36,9 @@ interface InsforgeProviderProps {
|
|
|
36
36
|
*/
|
|
37
37
|
afterSignInUrl?: string;
|
|
38
38
|
onAuthChange?: (user: InsforgeUser | null) => void;
|
|
39
|
-
onSignIn?: (authToken: string) => Promise<void>;
|
|
39
|
+
onSignIn?: (authToken: string, user: InsforgeUser) => Promise<void>;
|
|
40
40
|
onSignOut?: () => Promise<void>;
|
|
41
|
-
onRefresh?: (authToken: string) => Promise<void>;
|
|
41
|
+
onRefresh?: (authToken: string, user: InsforgeUser) => Promise<void>;
|
|
42
42
|
/**
|
|
43
43
|
* Initial auth state from server (for SSR hydration)
|
|
44
44
|
* @internal - Not intended for public use, used by Next.js package
|
package/dist/index.js
CHANGED
|
@@ -562,7 +562,7 @@ var InsforgeManager = class _InsforgeManager {
|
|
|
562
562
|
}
|
|
563
563
|
if (this.config.onRefresh && session.accessToken) {
|
|
564
564
|
try {
|
|
565
|
-
await this.config.onRefresh(session.accessToken);
|
|
565
|
+
await this.config.onRefresh(session.accessToken, session.user);
|
|
566
566
|
} catch (error) {
|
|
567
567
|
if (error instanceof Error) {
|
|
568
568
|
console.error("[InsforgeManager] Error syncing token on refresh:", error.message);
|
|
@@ -607,39 +607,22 @@ var InsforgeManager = class _InsforgeManager {
|
|
|
607
607
|
}
|
|
608
608
|
}
|
|
609
609
|
// Helper to handle auth success
|
|
610
|
-
async handleAuthSuccess(
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
const userData = {
|
|
614
|
-
id: userResult.data.user.id,
|
|
615
|
-
email: userResult.data.user.email,
|
|
616
|
-
profile: userResult.data.user.profile
|
|
617
|
-
};
|
|
618
|
-
this.user = userData;
|
|
610
|
+
async handleAuthSuccess(accessToken, user) {
|
|
611
|
+
if (user) {
|
|
612
|
+
this.user = user;
|
|
619
613
|
this.notifyListeners();
|
|
620
614
|
if (this.config.onAuthChange) {
|
|
621
|
-
this.config.onAuthChange(
|
|
615
|
+
this.config.onAuthChange(user);
|
|
622
616
|
}
|
|
623
617
|
if (this.config.onSignIn) {
|
|
624
618
|
try {
|
|
625
|
-
await this.config.onSignIn(
|
|
619
|
+
await this.config.onSignIn(accessToken, user);
|
|
626
620
|
} catch (error) {
|
|
627
621
|
if (error instanceof Error) {
|
|
628
622
|
console.error("[InsforgeManager] Error syncing token to cookie:", error.message);
|
|
629
623
|
}
|
|
630
624
|
}
|
|
631
625
|
}
|
|
632
|
-
} else if (fallbackUser) {
|
|
633
|
-
const userData = {
|
|
634
|
-
id: fallbackUser.id || "",
|
|
635
|
-
email: fallbackUser.email || "",
|
|
636
|
-
profile: fallbackUser.profile || null
|
|
637
|
-
};
|
|
638
|
-
this.user = userData;
|
|
639
|
-
this.notifyListeners();
|
|
640
|
-
if (this.config.onAuthChange) {
|
|
641
|
-
this.config.onAuthChange(userData);
|
|
642
|
-
}
|
|
643
626
|
}
|
|
644
627
|
}
|
|
645
628
|
// Business methods
|
|
@@ -654,7 +637,7 @@ var InsforgeManager = class _InsforgeManager {
|
|
|
654
637
|
sdkResult.data.user ? {
|
|
655
638
|
id: sdkResult.data.user.id,
|
|
656
639
|
email: sdkResult.data.user.email,
|
|
657
|
-
profile: sdkResult.data.user.profile
|
|
640
|
+
profile: sdkResult.data.user.profile ?? null
|
|
658
641
|
} : void 0
|
|
659
642
|
);
|
|
660
643
|
return sdkResult.data;
|
|
@@ -669,13 +652,16 @@ var InsforgeManager = class _InsforgeManager {
|
|
|
669
652
|
async signUp(email, password) {
|
|
670
653
|
const sdkResult = await this.sdk.auth.signUp({ email, password });
|
|
671
654
|
if (sdkResult.data) {
|
|
655
|
+
if (sdkResult.data.requireEmailVerification) {
|
|
656
|
+
return sdkResult.data;
|
|
657
|
+
}
|
|
672
658
|
if (sdkResult.data.accessToken) {
|
|
673
659
|
await this.handleAuthSuccess(
|
|
674
660
|
sdkResult.data.accessToken,
|
|
675
661
|
sdkResult.data.user ? {
|
|
676
662
|
id: sdkResult.data.user.id,
|
|
677
663
|
email: sdkResult.data.user.email,
|
|
678
|
-
profile: sdkResult.data.user.profile
|
|
664
|
+
profile: sdkResult.data.user.profile ?? null
|
|
679
665
|
} : void 0
|
|
680
666
|
);
|
|
681
667
|
}
|
|
@@ -754,21 +740,20 @@ var InsforgeManager = class _InsforgeManager {
|
|
|
754
740
|
async verifyEmail(otp, email) {
|
|
755
741
|
const sdkResult = await this.sdk.auth.verifyEmail({ otp, email: email || void 0 });
|
|
756
742
|
if (sdkResult.data) {
|
|
743
|
+
await this.handleAuthSuccess(
|
|
744
|
+
sdkResult.data.accessToken,
|
|
745
|
+
sdkResult.data.user ? {
|
|
746
|
+
id: sdkResult.data.user.id,
|
|
747
|
+
email: sdkResult.data.user.email,
|
|
748
|
+
profile: sdkResult.data.user.profile ?? null
|
|
749
|
+
} : void 0
|
|
750
|
+
);
|
|
757
751
|
return sdkResult.data;
|
|
758
752
|
} else {
|
|
759
753
|
return {
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
email: "",
|
|
764
|
-
emailVerified: false,
|
|
765
|
-
updatedAt: "",
|
|
766
|
-
metadata: null,
|
|
767
|
-
profile: null
|
|
768
|
-
},
|
|
769
|
-
accessToken: "",
|
|
770
|
-
redirectTo: void 0,
|
|
771
|
-
csrfToken: void 0
|
|
754
|
+
error: sdkResult.error?.message || "Failed to verify email",
|
|
755
|
+
statusCode: sdkResult.error?.statusCode,
|
|
756
|
+
errorCode: sdkResult.error?.error
|
|
772
757
|
};
|
|
773
758
|
}
|
|
774
759
|
}
|
|
@@ -2200,19 +2185,7 @@ function InsforgeProviderCore({
|
|
|
2200
2185
|
const unsubscribe = manager.subscribe((newState) => {
|
|
2201
2186
|
setState(newState);
|
|
2202
2187
|
});
|
|
2203
|
-
void manager.initialize()
|
|
2204
|
-
const params = new URLSearchParams(window.location.search);
|
|
2205
|
-
if (params.has("access_token")) {
|
|
2206
|
-
const url = new URL(window.location.href);
|
|
2207
|
-
url.searchParams.delete("access_token");
|
|
2208
|
-
url.searchParams.delete("user_id");
|
|
2209
|
-
url.searchParams.delete("email");
|
|
2210
|
-
url.searchParams.delete("name");
|
|
2211
|
-
url.searchParams.delete("csrf_token");
|
|
2212
|
-
url.searchParams.delete("error");
|
|
2213
|
-
window.history.replaceState({}, document.title, url.toString());
|
|
2214
|
-
}
|
|
2215
|
-
});
|
|
2188
|
+
void manager.initialize();
|
|
2216
2189
|
return () => {
|
|
2217
2190
|
unsubscribe();
|
|
2218
2191
|
};
|
|
@@ -2267,7 +2240,7 @@ function useInsforge() {
|
|
|
2267
2240
|
sendVerificationEmail: () => Promise.resolve(null),
|
|
2268
2241
|
sendResetPasswordEmail: () => Promise.resolve(null),
|
|
2269
2242
|
resetPassword: () => Promise.resolve(null),
|
|
2270
|
-
verifyEmail: () => Promise.resolve(
|
|
2243
|
+
verifyEmail: () => Promise.resolve({ error: "SSR mode" }),
|
|
2271
2244
|
exchangeResetPasswordToken: () => Promise.resolve({ error: { message: "SSR mode" } }),
|
|
2272
2245
|
loginWithOAuth: () => Promise.resolve(),
|
|
2273
2246
|
getPublicAuthConfig: () => Promise.resolve(null),
|
|
@@ -4151,7 +4124,7 @@ function SignInForm({
|
|
|
4151
4124
|
] })
|
|
4152
4125
|
] });
|
|
4153
4126
|
}
|
|
4154
|
-
function SignIn({ onError, ...uiProps }) {
|
|
4127
|
+
function SignIn({ onSuccess, onError, ...uiProps }) {
|
|
4155
4128
|
const { signIn, verifyEmail, loginWithOAuth } = useInsforge();
|
|
4156
4129
|
const { authConfig } = usePublicAuthConfig();
|
|
4157
4130
|
const [email, setEmail] = useState("");
|
|
@@ -4176,19 +4149,12 @@ function SignIn({ onError, ...uiProps }) {
|
|
|
4176
4149
|
}
|
|
4177
4150
|
throw new Error(result.error);
|
|
4178
4151
|
}
|
|
4179
|
-
const { user, accessToken,
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
-
const finalUrl = new URL(redirectTo || redirectUrl || "", window.location.origin);
|
|
4183
|
-
finalUrl.searchParams.set("access_token", accessToken);
|
|
4184
|
-
finalUrl.searchParams.set("user_id", user.id);
|
|
4185
|
-
finalUrl.searchParams.set("email", user.email);
|
|
4186
|
-
finalUrl.searchParams.set("name", user.profile?.name || "");
|
|
4187
|
-
if (csrfToken) {
|
|
4188
|
-
finalUrl.searchParams.set("csrf_token", csrfToken);
|
|
4189
|
-
}
|
|
4190
|
-
window.location.href = finalUrl.toString();
|
|
4152
|
+
const { redirectTo, user, accessToken, csrfToken } = result;
|
|
4153
|
+
if (onSuccess) {
|
|
4154
|
+
onSuccess(accessToken, user, csrfToken);
|
|
4191
4155
|
}
|
|
4156
|
+
const finalUrl = new URL(redirectTo || redirectUrl || "", window.location.origin);
|
|
4157
|
+
window.location.href = finalUrl.toString();
|
|
4192
4158
|
} catch (err) {
|
|
4193
4159
|
const errorMessage = err instanceof Error ? err.message : "Sign in failed";
|
|
4194
4160
|
setError(errorMessage);
|
|
@@ -4203,17 +4169,10 @@ function SignIn({ onError, ...uiProps }) {
|
|
|
4203
4169
|
setError("");
|
|
4204
4170
|
try {
|
|
4205
4171
|
const result = await verifyEmail(code, email);
|
|
4206
|
-
if (
|
|
4172
|
+
if ("error" in result) {
|
|
4207
4173
|
throw new Error("Verification failed");
|
|
4208
4174
|
}
|
|
4209
4175
|
const finalUrl = new URL(result.redirectTo || redirectUrl || "", window.location.origin);
|
|
4210
|
-
finalUrl.searchParams.set("access_token", result.accessToken);
|
|
4211
|
-
finalUrl.searchParams.set("user_id", result.user.id);
|
|
4212
|
-
finalUrl.searchParams.set("email", result.user.email);
|
|
4213
|
-
finalUrl.searchParams.set("name", result.user.profile?.name || "");
|
|
4214
|
-
if (result.csrfToken) {
|
|
4215
|
-
finalUrl.searchParams.set("csrf_token", result.csrfToken);
|
|
4216
|
-
}
|
|
4217
4176
|
window.location.href = finalUrl.toString();
|
|
4218
4177
|
} catch (err) {
|
|
4219
4178
|
const errorMessage = err instanceof Error ? err.message : "Invalid verification code";
|
|
@@ -4416,7 +4375,7 @@ function checkPasswordStrength(password) {
|
|
|
4416
4375
|
}
|
|
4417
4376
|
return { score, feedback };
|
|
4418
4377
|
}
|
|
4419
|
-
function SignUp({ onError, ...uiProps }) {
|
|
4378
|
+
function SignUp({ onSuccess, onError, ...uiProps }) {
|
|
4420
4379
|
const { signUp, verifyEmail, loginWithOAuth } = useInsforge();
|
|
4421
4380
|
const { authConfig } = usePublicAuthConfig();
|
|
4422
4381
|
const [email, setEmail] = useState("");
|
|
@@ -4462,21 +4421,17 @@ function SignUp({ onError, ...uiProps }) {
|
|
|
4462
4421
|
if ("error" in result) {
|
|
4463
4422
|
throw new Error(result.error);
|
|
4464
4423
|
}
|
|
4465
|
-
if (result.requireEmailVerification
|
|
4424
|
+
if (result.requireEmailVerification) {
|
|
4466
4425
|
setStep("awaiting-verification");
|
|
4467
4426
|
setLoading(false);
|
|
4468
4427
|
return;
|
|
4469
4428
|
}
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
finalUrl.searchParams.set("user_id", result.user.id);
|
|
4475
|
-
finalUrl.searchParams.set("email", result.user.email);
|
|
4476
|
-
finalUrl.searchParams.set("name", result.user.profile?.name || "");
|
|
4477
|
-
if (csrfToken) {
|
|
4478
|
-
finalUrl.searchParams.set("csrf_token", csrfToken);
|
|
4429
|
+
const { redirectTo, user, accessToken, csrfToken } = result;
|
|
4430
|
+
if (accessToken && user) {
|
|
4431
|
+
if (onSuccess) {
|
|
4432
|
+
onSuccess(accessToken, user, csrfToken);
|
|
4479
4433
|
}
|
|
4434
|
+
const finalUrl = new URL(redirectTo || redirectUrl || "", window.location.origin);
|
|
4480
4435
|
window.location.href = finalUrl.toString();
|
|
4481
4436
|
}
|
|
4482
4437
|
} catch (err) {
|
|
@@ -4493,17 +4448,10 @@ function SignUp({ onError, ...uiProps }) {
|
|
|
4493
4448
|
setError("");
|
|
4494
4449
|
try {
|
|
4495
4450
|
const result = await verifyEmail(code, email);
|
|
4496
|
-
if (
|
|
4451
|
+
if ("error" in result) {
|
|
4497
4452
|
throw new Error("Verification failed");
|
|
4498
4453
|
}
|
|
4499
4454
|
const finalUrl = new URL(result.redirectTo || redirectUrl || "", window.location.origin);
|
|
4500
|
-
finalUrl.searchParams.set("access_token", result.accessToken);
|
|
4501
|
-
finalUrl.searchParams.set("user_id", result.user.id);
|
|
4502
|
-
finalUrl.searchParams.set("email", result.user.email);
|
|
4503
|
-
finalUrl.searchParams.set("name", result.user.profile?.name || "");
|
|
4504
|
-
if (result.csrfToken) {
|
|
4505
|
-
finalUrl.searchParams.set("csrf_token", result.csrfToken);
|
|
4506
|
-
}
|
|
4507
4455
|
window.location.href = finalUrl.toString();
|
|
4508
4456
|
} catch (err) {
|
|
4509
4457
|
const errorMessage = err instanceof Error ? err.message : "Invalid verification code";
|
|
@@ -5077,8 +5025,8 @@ function VerifyEmail({ token: token2, onSuccess, onError, ...uiProps }) {
|
|
|
5077
5025
|
}
|
|
5078
5026
|
try {
|
|
5079
5027
|
const result = await verifyEmail(token2);
|
|
5080
|
-
if (
|
|
5081
|
-
const errorMessage = result
|
|
5028
|
+
if ("error" in result) {
|
|
5029
|
+
const errorMessage = result.error || "Email verification failed";
|
|
5082
5030
|
setError(errorMessage);
|
|
5083
5031
|
setStatus("error");
|
|
5084
5032
|
if (onError) {
|