@insforge/nextjs 0.6.8 → 0.7.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 +119 -112
- package/dist/api.d.mts +39 -0
- package/dist/api.d.ts +39 -0
- package/dist/api.js +4 -60
- package/dist/api.js.map +1 -1
- package/dist/api.mjs +3 -58
- package/dist/api.mjs.map +1 -1
- package/dist/index.d.mts +245 -0
- package/dist/index.d.ts +245 -0
- package/dist/index.js +101 -68
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +101 -67
- package/dist/index.mjs.map +1 -1
- package/dist/middleware.d.mts +20 -0
- package/dist/middleware.d.ts +20 -0
- package/dist/middleware.js +17 -21
- package/dist/middleware.js.map +1 -1
- package/dist/middleware.mjs +17 -21
- package/dist/middleware.mjs.map +1 -1
- package/package.json +5 -4
package/dist/index.mjs
CHANGED
|
@@ -5,19 +5,6 @@ import { createContext, useContext, useEffect, useState, useCallback, useRef } f
|
|
|
5
5
|
import { createClient } from "@insforge/sdk";
|
|
6
6
|
import { jsx } from "react/jsx-runtime";
|
|
7
7
|
var InsforgeContext = createContext(void 0);
|
|
8
|
-
function getTokenFromSDK() {
|
|
9
|
-
console.log("[InsforgeProvider] Getting token from SDK");
|
|
10
|
-
if (typeof window === "undefined") return null;
|
|
11
|
-
console.log("[InsforgeProvider] Window:", window);
|
|
12
|
-
try {
|
|
13
|
-
const token = localStorage.getItem("insforge-auth-token");
|
|
14
|
-
console.log("[InsforgeProvider] Token:", token);
|
|
15
|
-
return token;
|
|
16
|
-
} catch (error) {
|
|
17
|
-
console.error("[InsforgeProvider] Error getting token from SDK:", error);
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
8
|
async function syncTokenToCookie(token) {
|
|
22
9
|
try {
|
|
23
10
|
const response = await fetch("/api/auth", {
|
|
@@ -48,11 +35,13 @@ function InsforgeProvider({
|
|
|
48
35
|
const [user, setUser] = useState(null);
|
|
49
36
|
const [session, setSession] = useState(null);
|
|
50
37
|
const [isLoaded, setIsLoaded] = useState(false);
|
|
51
|
-
const refreshIntervalRef = useRef();
|
|
38
|
+
const refreshIntervalRef = useRef(null);
|
|
52
39
|
const [insforge] = useState(() => createClient({ baseUrl }));
|
|
53
40
|
const loadAuthState = useCallback(async () => {
|
|
54
41
|
try {
|
|
55
|
-
const
|
|
42
|
+
const sessionResult = insforge.auth.getCurrentSession();
|
|
43
|
+
const session2 = sessionResult.data?.session;
|
|
44
|
+
const token = session2?.accessToken || null;
|
|
56
45
|
if (!token) {
|
|
57
46
|
setUser(null);
|
|
58
47
|
setSession(null);
|
|
@@ -67,7 +56,6 @@ function InsforgeProvider({
|
|
|
67
56
|
try {
|
|
68
57
|
const cachedData = JSON.parse(cachedUserStr);
|
|
69
58
|
if (cachedData.user) {
|
|
70
|
-
console.log("[InsforgeProvider] Loading user from cache");
|
|
71
59
|
const userData = {
|
|
72
60
|
id: cachedData.user.id,
|
|
73
61
|
email: cachedData.user.email,
|
|
@@ -97,7 +85,6 @@ function InsforgeProvider({
|
|
|
97
85
|
}
|
|
98
86
|
const userResult = await insforge.auth.getCurrentUser();
|
|
99
87
|
if (userResult.data) {
|
|
100
|
-
console.log("[InsforgeProvider] User data refreshed from API");
|
|
101
88
|
const userData = {
|
|
102
89
|
id: userResult.data.user.id,
|
|
103
90
|
email: userResult.data.user.email,
|
|
@@ -158,28 +145,52 @@ function InsforgeProvider({
|
|
|
158
145
|
async (email, password) => {
|
|
159
146
|
const sdkResult = await insforge.auth.signInWithPassword({ email, password });
|
|
160
147
|
if (sdkResult.data) {
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
148
|
+
const userResult = await insforge.auth.getCurrentUser();
|
|
149
|
+
if (userResult.data) {
|
|
150
|
+
const userData = {
|
|
151
|
+
id: userResult.data.user.id,
|
|
152
|
+
email: userResult.data.user.email,
|
|
153
|
+
name: userResult.data.user.name || void 0,
|
|
154
|
+
createdAt: userResult.data.user.createdAt,
|
|
155
|
+
updatedAt: userResult.data.user.updatedAt,
|
|
156
|
+
...userResult.data.profile
|
|
157
|
+
// Include profile fields (nickname, avatar_url, etc.)
|
|
158
|
+
};
|
|
159
|
+
const sessionData = {
|
|
160
|
+
userId: userResult.data.user.id,
|
|
161
|
+
token: sdkResult.data.accessToken || "",
|
|
162
|
+
expiresAt: "",
|
|
163
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
164
|
+
};
|
|
165
|
+
setUser(userData);
|
|
166
|
+
setSession(sessionData);
|
|
167
|
+
localStorage.setItem("insforge-user-profile", JSON.stringify(userResult.data));
|
|
168
|
+
if (onAuthChange) {
|
|
169
|
+
onAuthChange(userData);
|
|
170
|
+
}
|
|
171
|
+
try {
|
|
172
|
+
await syncTokenToCookie(sdkResult.data.accessToken || "");
|
|
173
|
+
} catch (error) {
|
|
174
|
+
console.error("Please add /api/auth route to your server to sync token to cookie:", error);
|
|
175
|
+
}
|
|
176
|
+
} else {
|
|
177
|
+
const userData = {
|
|
178
|
+
id: sdkResult.data.user.id,
|
|
179
|
+
email: sdkResult.data.user.email,
|
|
180
|
+
name: sdkResult.data.user.name || void 0,
|
|
181
|
+
createdAt: sdkResult.data.user.createdAt,
|
|
182
|
+
updatedAt: sdkResult.data.user.updatedAt
|
|
183
|
+
};
|
|
184
|
+
setUser(userData);
|
|
185
|
+
setSession({
|
|
186
|
+
userId: sdkResult.data.user.id,
|
|
187
|
+
token: sdkResult.data.accessToken || "",
|
|
188
|
+
expiresAt: "",
|
|
189
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
190
|
+
});
|
|
191
|
+
if (onAuthChange) {
|
|
192
|
+
onAuthChange(userData);
|
|
193
|
+
}
|
|
183
194
|
}
|
|
184
195
|
} else {
|
|
185
196
|
const errorMessage = sdkResult.error?.message || "Invalid email or password";
|
|
@@ -192,27 +203,51 @@ function InsforgeProvider({
|
|
|
192
203
|
async (email, password) => {
|
|
193
204
|
const sdkResult = await insforge.auth.signUp({ email, password });
|
|
194
205
|
if (sdkResult.data) {
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
206
|
+
const userResult = await insforge.auth.getCurrentUser();
|
|
207
|
+
if (userResult.data) {
|
|
208
|
+
const userData = {
|
|
209
|
+
id: userResult.data.user.id,
|
|
210
|
+
email: userResult.data.user.email,
|
|
211
|
+
name: userResult.data.user.name || void 0,
|
|
212
|
+
createdAt: userResult.data.user.createdAt,
|
|
213
|
+
updatedAt: userResult.data.user.updatedAt,
|
|
214
|
+
...userResult.data.profile
|
|
215
|
+
// Include profile fields (nickname, avatar_url, etc.)
|
|
216
|
+
};
|
|
217
|
+
const sessionData = {
|
|
218
|
+
userId: userResult.data.user.id,
|
|
219
|
+
token: sdkResult.data.accessToken || "",
|
|
220
|
+
expiresAt: "",
|
|
221
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
222
|
+
};
|
|
223
|
+
setUser(userData);
|
|
224
|
+
setSession(sessionData);
|
|
225
|
+
localStorage.setItem("insforge-user-profile", JSON.stringify(userResult.data));
|
|
226
|
+
if (onAuthChange) {
|
|
227
|
+
onAuthChange(userData);
|
|
228
|
+
}
|
|
229
|
+
try {
|
|
230
|
+
await syncTokenToCookie(sdkResult.data.accessToken || "");
|
|
231
|
+
} catch (error) {
|
|
232
|
+
}
|
|
233
|
+
} else {
|
|
234
|
+
const userData = {
|
|
235
|
+
id: sdkResult.data.user.id,
|
|
236
|
+
email: sdkResult.data.user.email,
|
|
237
|
+
name: sdkResult.data.user.name || void 0,
|
|
238
|
+
createdAt: sdkResult.data.user.createdAt,
|
|
239
|
+
updatedAt: sdkResult.data.user.updatedAt
|
|
240
|
+
};
|
|
241
|
+
setUser(userData);
|
|
242
|
+
setSession({
|
|
243
|
+
userId: sdkResult.data.user.id,
|
|
244
|
+
token: sdkResult.data.accessToken || "",
|
|
245
|
+
expiresAt: "",
|
|
246
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
247
|
+
});
|
|
248
|
+
if (onAuthChange) {
|
|
249
|
+
onAuthChange(userData);
|
|
250
|
+
}
|
|
216
251
|
}
|
|
217
252
|
} else {
|
|
218
253
|
const errorMessage = sdkResult.error?.message || "Sign up failed";
|
|
@@ -300,6 +335,10 @@ function useSession() {
|
|
|
300
335
|
return { session, isLoaded };
|
|
301
336
|
}
|
|
302
337
|
|
|
338
|
+
// src/components/SignIn.tsx
|
|
339
|
+
import { useState as useState4 } from "react";
|
|
340
|
+
import { createClient as createClient3 } from "@insforge/sdk";
|
|
341
|
+
|
|
303
342
|
// src/hooks/useOAuthProviders.ts
|
|
304
343
|
import { useState as useState2, useEffect as useEffect2 } from "react";
|
|
305
344
|
import { createClient as createClient2 } from "@insforge/sdk";
|
|
@@ -318,7 +357,8 @@ function useOAuthProviders() {
|
|
|
318
357
|
console.warn("[useOAuthProviders] Failed to fetch OAuth providers:", error);
|
|
319
358
|
setProviders([]);
|
|
320
359
|
} else if (data) {
|
|
321
|
-
|
|
360
|
+
const configuredProviders = data.filter((p) => p.isConfigured).map((p) => p.provider);
|
|
361
|
+
setProviders(configuredProviders);
|
|
322
362
|
} else {
|
|
323
363
|
setProviders([]);
|
|
324
364
|
}
|
|
@@ -339,10 +379,6 @@ function useOAuthProviders() {
|
|
|
339
379
|
return { providers, isLoaded };
|
|
340
380
|
}
|
|
341
381
|
|
|
342
|
-
// src/components/SignIn.tsx
|
|
343
|
-
import { useState as useState4 } from "react";
|
|
344
|
-
import { createClient as createClient3 } from "@insforge/sdk";
|
|
345
|
-
|
|
346
382
|
// src/components/auth/AuthBranding.tsx
|
|
347
383
|
import Link from "next/link";
|
|
348
384
|
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
@@ -966,7 +1002,6 @@ function SignIn({
|
|
|
966
1002
|
provider,
|
|
967
1003
|
redirectTo
|
|
968
1004
|
});
|
|
969
|
-
console.log("handleOAuth result", result);
|
|
970
1005
|
} catch (err) {
|
|
971
1006
|
const errorMessage = err.message || `${provider} sign in failed`;
|
|
972
1007
|
setError(errorMessage);
|
|
@@ -1304,7 +1339,6 @@ export {
|
|
|
1304
1339
|
isProviderSupported,
|
|
1305
1340
|
useAuth,
|
|
1306
1341
|
useInsforge,
|
|
1307
|
-
useOAuthProviders,
|
|
1308
1342
|
useSession,
|
|
1309
1343
|
useUser,
|
|
1310
1344
|
validatePasswordStrength
|