@insforge/react 0.2.4 → 0.2.5
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/components.js +26 -3
- package/dist/components.js.map +1 -1
- package/dist/components.mjs +26 -3
- package/dist/components.mjs.map +1 -1
- package/dist/hooks.js.map +1 -1
- package/dist/hooks.mjs.map +1 -1
- package/dist/index.d.mts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +91 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +91 -3
- package/dist/index.mjs.map +1 -1
- package/dist/router.js +26 -3
- package/dist/router.js.map +1 -1
- package/dist/router.mjs +26 -3
- package/dist/router.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -158,6 +158,70 @@ function InsforgeProvider({
|
|
|
158
158
|
},
|
|
159
159
|
[insforge, onAuthChange, syncTokenToCookie]
|
|
160
160
|
);
|
|
161
|
+
const handleAuthCallback = useCallback(
|
|
162
|
+
async (params) => {
|
|
163
|
+
try {
|
|
164
|
+
await insforge.auth.setSession({
|
|
165
|
+
accessToken: params.accessToken,
|
|
166
|
+
user: {
|
|
167
|
+
id: params.userId || "",
|
|
168
|
+
email: params.email || "",
|
|
169
|
+
name: params.name || "",
|
|
170
|
+
emailVerified: false,
|
|
171
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
172
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
const userResult = await insforge.auth.getCurrentUser();
|
|
176
|
+
if (!userResult.data) {
|
|
177
|
+
await insforge.auth.signOut();
|
|
178
|
+
if (clearCookie) {
|
|
179
|
+
try {
|
|
180
|
+
await clearCookie();
|
|
181
|
+
} catch (error) {
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return { success: false, error: "invalid_token" };
|
|
185
|
+
}
|
|
186
|
+
const profile = userResult.data.profile;
|
|
187
|
+
const userData = {
|
|
188
|
+
id: userResult.data.user.id,
|
|
189
|
+
email: userResult.data.user.email,
|
|
190
|
+
name: profile?.nickname || params.name || "",
|
|
191
|
+
avatarUrl: profile?.avatarUrl || ""
|
|
192
|
+
};
|
|
193
|
+
setUser(userData);
|
|
194
|
+
if (onAuthChange) {
|
|
195
|
+
onAuthChange(userData);
|
|
196
|
+
}
|
|
197
|
+
if (syncTokenToCookie) {
|
|
198
|
+
try {
|
|
199
|
+
await syncTokenToCookie(params.accessToken);
|
|
200
|
+
} catch (error) {
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return { success: true };
|
|
204
|
+
} catch (error) {
|
|
205
|
+
console.error("[InsforgeProvider] Auth callback failed:", error);
|
|
206
|
+
await insforge.auth.signOut();
|
|
207
|
+
if (clearCookie) {
|
|
208
|
+
try {
|
|
209
|
+
await clearCookie();
|
|
210
|
+
} catch (error2) {
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
setUser(null);
|
|
214
|
+
if (onAuthChange) {
|
|
215
|
+
onAuthChange(null);
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
success: false,
|
|
219
|
+
error: error instanceof Error ? error.message : "authentication_failed"
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
[insforge, onAuthChange, syncTokenToCookie, clearCookie]
|
|
224
|
+
);
|
|
161
225
|
const signIn = useCallback(
|
|
162
226
|
async (email, password) => {
|
|
163
227
|
const sdkResult = await insforge.auth.signInWithPassword({
|
|
@@ -281,6 +345,7 @@ function InsforgeProvider({
|
|
|
281
345
|
signOut,
|
|
282
346
|
updateUser,
|
|
283
347
|
reloadAuth: loadAuthState,
|
|
348
|
+
handleAuthCallback,
|
|
284
349
|
baseUrl,
|
|
285
350
|
sendPasswordResetCode,
|
|
286
351
|
resetPassword,
|
|
@@ -1693,7 +1758,7 @@ function InsforgeCallback({
|
|
|
1693
1758
|
onRedirect
|
|
1694
1759
|
}) {
|
|
1695
1760
|
const isProcessingRef = useRef(false);
|
|
1696
|
-
const {
|
|
1761
|
+
const { handleAuthCallback } = useInsforge();
|
|
1697
1762
|
useEffect(() => {
|
|
1698
1763
|
const processCallback = async () => {
|
|
1699
1764
|
if (isProcessingRef.current) return;
|
|
@@ -1713,7 +1778,30 @@ function InsforgeCallback({
|
|
|
1713
1778
|
}
|
|
1714
1779
|
return;
|
|
1715
1780
|
}
|
|
1716
|
-
const
|
|
1781
|
+
const accessToken = searchParams.get("access_token") || searchParams.get("auth_token");
|
|
1782
|
+
const userId = searchParams.get("user_id");
|
|
1783
|
+
const email = searchParams.get("email");
|
|
1784
|
+
const name = searchParams.get("name");
|
|
1785
|
+
if (!accessToken) {
|
|
1786
|
+
const errorMsg = "no_token";
|
|
1787
|
+
if (onError) {
|
|
1788
|
+
onError(errorMsg);
|
|
1789
|
+
} else {
|
|
1790
|
+
const errorUrl = "/?error=" + encodeURIComponent(errorMsg);
|
|
1791
|
+
if (onRedirect) {
|
|
1792
|
+
onRedirect(errorUrl);
|
|
1793
|
+
} else {
|
|
1794
|
+
window.location.href = errorUrl;
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
return;
|
|
1798
|
+
}
|
|
1799
|
+
const result = await handleAuthCallback({
|
|
1800
|
+
accessToken,
|
|
1801
|
+
userId: userId || void 0,
|
|
1802
|
+
email: email || void 0,
|
|
1803
|
+
name: name || void 0
|
|
1804
|
+
});
|
|
1717
1805
|
if (!result.success) {
|
|
1718
1806
|
const errorMsg = result.error || "authentication_failed";
|
|
1719
1807
|
if (onError) {
|
|
@@ -1742,7 +1830,7 @@ function InsforgeCallback({
|
|
|
1742
1830
|
}
|
|
1743
1831
|
};
|
|
1744
1832
|
processCallback();
|
|
1745
|
-
}, []);
|
|
1833
|
+
}, [handleAuthCallback, redirectTo, onSuccess, onError, onRedirect]);
|
|
1746
1834
|
const defaultLoading = /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center min-h-screen", children: /* @__PURE__ */ jsxs("div", { className: "text-center", children: [
|
|
1747
1835
|
/* @__PURE__ */ jsx("h2", { className: "text-2xl font-semibold mb-4", children: "Completing authentication..." }),
|
|
1748
1836
|
/* @__PURE__ */ jsx("div", { className: "animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto" })
|