@insforge/nextjs 0.6.9 → 0.7.1
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 +121 -112
- package/dist/api.d.mts +1 -12
- package/dist/api.d.ts +1 -12
- package/dist/api.js +6 -62
- package/dist/api.js.map +1 -1
- package/dist/api.mjs +5 -60
- package/dist/api.mjs.map +1 -1
- package/dist/index.d.mts +14 -19
- package/dist/index.d.ts +14 -19
- package/dist/index.js +218 -132
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +215 -128
- package/dist/index.mjs.map +1 -1
- 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 +4 -3
package/dist/index.js
CHANGED
|
@@ -58,7 +58,6 @@ __export(src_exports, {
|
|
|
58
58
|
isProviderSupported: () => isProviderSupported,
|
|
59
59
|
useAuth: () => useAuth,
|
|
60
60
|
useInsforge: () => useInsforge,
|
|
61
|
-
useOAuthProviders: () => useOAuthProviders,
|
|
62
61
|
useSession: () => useSession,
|
|
63
62
|
useUser: () => useUser,
|
|
64
63
|
validatePasswordStrength: () => validatePasswordStrength
|
|
@@ -70,19 +69,6 @@ var import_react = require("react");
|
|
|
70
69
|
var import_sdk = require("@insforge/sdk");
|
|
71
70
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
72
71
|
var InsforgeContext = (0, import_react.createContext)(void 0);
|
|
73
|
-
function getTokenFromSDK() {
|
|
74
|
-
console.log("[InsforgeProvider] Getting token from SDK");
|
|
75
|
-
if (typeof window === "undefined") return null;
|
|
76
|
-
console.log("[InsforgeProvider] Window:", window);
|
|
77
|
-
try {
|
|
78
|
-
const token = localStorage.getItem("insforge-auth-token");
|
|
79
|
-
console.log("[InsforgeProvider] Token:", token);
|
|
80
|
-
return token;
|
|
81
|
-
} catch (error) {
|
|
82
|
-
console.error("[InsforgeProvider] Error getting token from SDK:", error);
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
72
|
async function syncTokenToCookie(token) {
|
|
87
73
|
try {
|
|
88
74
|
const response = await fetch("/api/auth", {
|
|
@@ -117,7 +103,9 @@ function InsforgeProvider({
|
|
|
117
103
|
const [insforge] = (0, import_react.useState)(() => (0, import_sdk.createClient)({ baseUrl }));
|
|
118
104
|
const loadAuthState = (0, import_react.useCallback)(async () => {
|
|
119
105
|
try {
|
|
120
|
-
const
|
|
106
|
+
const sessionResult = insforge.auth.getCurrentSession();
|
|
107
|
+
const session2 = sessionResult.data?.session;
|
|
108
|
+
const token = session2?.accessToken || null;
|
|
121
109
|
if (!token) {
|
|
122
110
|
setUser(null);
|
|
123
111
|
setSession(null);
|
|
@@ -132,13 +120,11 @@ function InsforgeProvider({
|
|
|
132
120
|
try {
|
|
133
121
|
const cachedData = JSON.parse(cachedUserStr);
|
|
134
122
|
if (cachedData.user) {
|
|
135
|
-
console.log("[InsforgeProvider] Loading user from cache");
|
|
136
123
|
const userData = {
|
|
137
124
|
id: cachedData.user.id,
|
|
138
125
|
email: cachedData.user.email,
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
...cachedData.profile
|
|
126
|
+
name: cachedData.profile?.nickname || "",
|
|
127
|
+
avatarUrl: cachedData.profile?.avatar_url || ""
|
|
142
128
|
};
|
|
143
129
|
setUser(userData);
|
|
144
130
|
setSession({
|
|
@@ -162,13 +148,11 @@ function InsforgeProvider({
|
|
|
162
148
|
}
|
|
163
149
|
const userResult = await insforge.auth.getCurrentUser();
|
|
164
150
|
if (userResult.data) {
|
|
165
|
-
console.log("[InsforgeProvider] User data refreshed from API");
|
|
166
151
|
const userData = {
|
|
167
152
|
id: userResult.data.user.id,
|
|
168
153
|
email: userResult.data.user.email,
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
...userResult.data.profile
|
|
154
|
+
name: userResult.data.profile?.nickname || "",
|
|
155
|
+
avatarUrl: userResult.data.profile?.avatar_url || ""
|
|
172
156
|
};
|
|
173
157
|
setUser(userData);
|
|
174
158
|
setSession({
|
|
@@ -219,72 +203,90 @@ function InsforgeProvider({
|
|
|
219
203
|
}
|
|
220
204
|
};
|
|
221
205
|
}, []);
|
|
222
|
-
const
|
|
223
|
-
async (
|
|
224
|
-
const
|
|
225
|
-
if (
|
|
206
|
+
const handleAuthSuccess = (0, import_react.useCallback)(
|
|
207
|
+
async (authToken, fallbackUser) => {
|
|
208
|
+
const userResult = await insforge.auth.getCurrentUser();
|
|
209
|
+
if (userResult.data) {
|
|
226
210
|
const userData = {
|
|
227
|
-
id:
|
|
228
|
-
email:
|
|
229
|
-
name:
|
|
230
|
-
|
|
231
|
-
updatedAt: sdkResult.data.user.updatedAt
|
|
211
|
+
id: userResult.data.user.id,
|
|
212
|
+
email: userResult.data.user.email,
|
|
213
|
+
name: userResult.data.profile?.nickname || "",
|
|
214
|
+
avatarUrl: userResult.data.profile?.avatar_url || ""
|
|
232
215
|
};
|
|
233
216
|
const sessionData = {
|
|
234
|
-
userId:
|
|
235
|
-
token:
|
|
217
|
+
userId: userResult.data.user.id,
|
|
218
|
+
token: authToken,
|
|
236
219
|
expiresAt: "",
|
|
237
220
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
238
221
|
};
|
|
239
222
|
setUser(userData);
|
|
240
223
|
setSession(sessionData);
|
|
224
|
+
localStorage.setItem("insforge-user-profile", JSON.stringify(userResult.data));
|
|
241
225
|
if (onAuthChange) {
|
|
242
226
|
onAuthChange(userData);
|
|
243
227
|
}
|
|
244
228
|
try {
|
|
245
|
-
await syncTokenToCookie(
|
|
229
|
+
await syncTokenToCookie(authToken);
|
|
246
230
|
} catch (error) {
|
|
247
|
-
console.error("Please add /api/auth route to your server to sync token to cookie:", error);
|
|
248
231
|
}
|
|
232
|
+
} else if (fallbackUser) {
|
|
233
|
+
const userData = {
|
|
234
|
+
id: fallbackUser.id || "",
|
|
235
|
+
email: fallbackUser.email || "",
|
|
236
|
+
name: fallbackUser.name || "",
|
|
237
|
+
avatarUrl: ""
|
|
238
|
+
};
|
|
239
|
+
setUser(userData);
|
|
240
|
+
setSession({
|
|
241
|
+
userId: fallbackUser.id || "",
|
|
242
|
+
token: authToken,
|
|
243
|
+
expiresAt: "",
|
|
244
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
245
|
+
});
|
|
246
|
+
if (onAuthChange) {
|
|
247
|
+
onAuthChange(userData);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
[insforge, onAuthChange]
|
|
252
|
+
);
|
|
253
|
+
const signIn = (0, import_react.useCallback)(
|
|
254
|
+
async (email, password) => {
|
|
255
|
+
const sdkResult = await insforge.auth.signInWithPassword({ email, password });
|
|
256
|
+
if (sdkResult.data) {
|
|
257
|
+
await handleAuthSuccess(
|
|
258
|
+
sdkResult.data.accessToken || "",
|
|
259
|
+
sdkResult.data.user ? {
|
|
260
|
+
id: sdkResult.data.user.id,
|
|
261
|
+
email: sdkResult.data.user.email,
|
|
262
|
+
name: sdkResult.data.user.name
|
|
263
|
+
} : void 0
|
|
264
|
+
);
|
|
249
265
|
} else {
|
|
250
266
|
const errorMessage = sdkResult.error?.message || "Invalid email or password";
|
|
251
267
|
throw new Error(errorMessage);
|
|
252
268
|
}
|
|
253
269
|
},
|
|
254
|
-
[insforge,
|
|
270
|
+
[insforge, handleAuthSuccess]
|
|
255
271
|
);
|
|
256
272
|
const signUp = (0, import_react.useCallback)(
|
|
257
273
|
async (email, password) => {
|
|
258
274
|
const sdkResult = await insforge.auth.signUp({ email, password });
|
|
259
275
|
if (sdkResult.data) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
userId: sdkResult.data.user.id,
|
|
269
|
-
token: sdkResult.data.accessToken,
|
|
270
|
-
expiresAt: "",
|
|
271
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
272
|
-
};
|
|
273
|
-
setUser(userData);
|
|
274
|
-
setSession(sessionData);
|
|
275
|
-
if (onAuthChange) {
|
|
276
|
-
onAuthChange(userData);
|
|
277
|
-
}
|
|
278
|
-
try {
|
|
279
|
-
await syncTokenToCookie(sdkResult.data.accessToken);
|
|
280
|
-
} catch (error) {
|
|
281
|
-
}
|
|
276
|
+
await handleAuthSuccess(
|
|
277
|
+
sdkResult.data.accessToken || "",
|
|
278
|
+
sdkResult.data.user ? {
|
|
279
|
+
id: sdkResult.data.user.id,
|
|
280
|
+
email: sdkResult.data.user.email,
|
|
281
|
+
name: sdkResult.data.user.name
|
|
282
|
+
} : void 0
|
|
283
|
+
);
|
|
282
284
|
} else {
|
|
283
285
|
const errorMessage = sdkResult.error?.message || "Sign up failed";
|
|
284
286
|
throw new Error(errorMessage);
|
|
285
287
|
}
|
|
286
288
|
},
|
|
287
|
-
[insforge,
|
|
289
|
+
[insforge, handleAuthSuccess]
|
|
288
290
|
);
|
|
289
291
|
const signOut = (0, import_react.useCallback)(async () => {
|
|
290
292
|
await insforge.auth.signOut();
|
|
@@ -303,7 +305,10 @@ function InsforgeProvider({
|
|
|
303
305
|
const updateUser = (0, import_react.useCallback)(
|
|
304
306
|
async (data) => {
|
|
305
307
|
if (!user) throw new Error("No user signed in");
|
|
306
|
-
const result = await insforge.auth.setProfile(
|
|
308
|
+
const result = await insforge.auth.setProfile({
|
|
309
|
+
nickname: data.name || "",
|
|
310
|
+
avatar_url: data.avatarUrl || ""
|
|
311
|
+
});
|
|
307
312
|
if (result.data) {
|
|
308
313
|
const updatedUser = { ...user, ...result.data };
|
|
309
314
|
setUser(updatedUser);
|
|
@@ -365,8 +370,13 @@ function useSession() {
|
|
|
365
370
|
return { session, isLoaded };
|
|
366
371
|
}
|
|
367
372
|
|
|
373
|
+
// src/components/SignIn.tsx
|
|
374
|
+
var import_react6 = require("react");
|
|
375
|
+
var import_sdk4 = require("@insforge/sdk");
|
|
376
|
+
|
|
368
377
|
// src/hooks/useOAuthProviders.ts
|
|
369
378
|
var import_react2 = require("react");
|
|
379
|
+
var import_sdk2 = require("@insforge/sdk");
|
|
370
380
|
function useOAuthProviders() {
|
|
371
381
|
const { baseUrl } = useInsforge();
|
|
372
382
|
const [providers, setProviders] = (0, import_react2.useState)([]);
|
|
@@ -375,25 +385,21 @@ function useOAuthProviders() {
|
|
|
375
385
|
let mounted = true;
|
|
376
386
|
async function fetchProviders() {
|
|
377
387
|
try {
|
|
378
|
-
const
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
setProviders(result.data);
|
|
390
|
-
} else {
|
|
391
|
-
setProviders([]);
|
|
392
|
-
}
|
|
393
|
-
setIsLoaded(true);
|
|
388
|
+
const insforge = (0, import_sdk2.createClient)({ baseUrl });
|
|
389
|
+
const { data, error } = await insforge.auth.getOAuthProviders();
|
|
390
|
+
if (!mounted) return;
|
|
391
|
+
if (error) {
|
|
392
|
+
console.warn("[useOAuthProviders] Failed to fetch OAuth providers:", error);
|
|
393
|
+
setProviders([]);
|
|
394
|
+
} else if (data) {
|
|
395
|
+
const providerNames = data.map((p) => p.provider);
|
|
396
|
+
setProviders(providerNames);
|
|
397
|
+
} else {
|
|
398
|
+
setProviders([]);
|
|
394
399
|
}
|
|
400
|
+
setIsLoaded(true);
|
|
395
401
|
} catch (error) {
|
|
396
|
-
console.warn("[useOAuthProviders]
|
|
402
|
+
console.warn("[useOAuthProviders] Unexpected error:", error);
|
|
397
403
|
if (mounted) {
|
|
398
404
|
setProviders([]);
|
|
399
405
|
setIsLoaded(true);
|
|
@@ -408,9 +414,42 @@ function useOAuthProviders() {
|
|
|
408
414
|
return { providers, isLoaded };
|
|
409
415
|
}
|
|
410
416
|
|
|
411
|
-
// src/
|
|
412
|
-
var
|
|
413
|
-
var
|
|
417
|
+
// src/hooks/useEmailAuthConfig.ts
|
|
418
|
+
var import_react3 = require("react");
|
|
419
|
+
var import_sdk3 = require("@insforge/sdk");
|
|
420
|
+
function useEmailAuthConfig() {
|
|
421
|
+
const { baseUrl } = useInsforge();
|
|
422
|
+
const [config, setConfig] = (0, import_react3.useState)(null);
|
|
423
|
+
const [isLoaded, setIsLoaded] = (0, import_react3.useState)(false);
|
|
424
|
+
(0, import_react3.useEffect)(() => {
|
|
425
|
+
let mounted = true;
|
|
426
|
+
async function fetchConfig() {
|
|
427
|
+
try {
|
|
428
|
+
const insforge = (0, import_sdk3.createClient)({ baseUrl });
|
|
429
|
+
const { data, error } = await insforge.auth.getEmailAuthConfig();
|
|
430
|
+
if (!mounted) return;
|
|
431
|
+
if (error) {
|
|
432
|
+
console.warn("[useEmailAuthConfig] Failed to fetch email auth config:", error);
|
|
433
|
+
setConfig(null);
|
|
434
|
+
} else {
|
|
435
|
+
setConfig(data);
|
|
436
|
+
}
|
|
437
|
+
setIsLoaded(true);
|
|
438
|
+
} catch (error) {
|
|
439
|
+
console.warn("[useEmailAuthConfig] Unexpected error:", error);
|
|
440
|
+
if (mounted) {
|
|
441
|
+
setConfig(null);
|
|
442
|
+
setIsLoaded(true);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
fetchConfig();
|
|
447
|
+
return () => {
|
|
448
|
+
mounted = false;
|
|
449
|
+
};
|
|
450
|
+
}, [baseUrl]);
|
|
451
|
+
return { config, isLoaded };
|
|
452
|
+
}
|
|
414
453
|
|
|
415
454
|
// src/components/auth/AuthBranding.tsx
|
|
416
455
|
var import_link = __toESM(require("next/link"));
|
|
@@ -522,35 +561,59 @@ function AuthFormField({ label, id, className = "", ...props }) {
|
|
|
522
561
|
}
|
|
523
562
|
|
|
524
563
|
// src/components/auth/AuthPasswordField.tsx
|
|
525
|
-
var
|
|
564
|
+
var import_react4 = require("react");
|
|
526
565
|
var import_lucide_react3 = require("lucide-react");
|
|
527
566
|
|
|
528
567
|
// src/components/auth/AuthPasswordStrengthIndicator.tsx
|
|
529
568
|
var import_lucide_react2 = require("lucide-react");
|
|
530
569
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
},
|
|
544
|
-
{
|
|
545
|
-
label: "8 characters or more",
|
|
546
|
-
test: (pwd) => pwd.length >= 8
|
|
570
|
+
function createRequirements(config) {
|
|
571
|
+
const requirements = [];
|
|
572
|
+
const minLength = config.passwordMinLength;
|
|
573
|
+
const requireUppercase = config.requireUppercase;
|
|
574
|
+
const requireLowercase = config.requireLowercase;
|
|
575
|
+
const requireNumber = config.requireNumber;
|
|
576
|
+
const requireSpecialChar = config.requireSpecialChar;
|
|
577
|
+
if (requireUppercase) {
|
|
578
|
+
requirements.push({
|
|
579
|
+
label: "At least 1 Uppercase letter",
|
|
580
|
+
test: (pwd) => /[A-Z]/.test(pwd)
|
|
581
|
+
});
|
|
547
582
|
}
|
|
548
|
-
|
|
549
|
-
|
|
583
|
+
if (requireLowercase) {
|
|
584
|
+
requirements.push({
|
|
585
|
+
label: "At least 1 Lowercase letter",
|
|
586
|
+
test: (pwd) => /[a-z]/.test(pwd)
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
if (requireNumber) {
|
|
590
|
+
requirements.push({
|
|
591
|
+
label: "At least 1 Number",
|
|
592
|
+
test: (pwd) => /\d/.test(pwd)
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
if (requireSpecialChar) {
|
|
596
|
+
requirements.push({
|
|
597
|
+
label: "Special character (e.g. !?<>@#$%)",
|
|
598
|
+
test: (pwd) => /[!@#$%^&*()_+\-=[\]{};\\|,.<>/?]/.test(pwd)
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
requirements.push({
|
|
602
|
+
label: `${minLength} characters or more`,
|
|
603
|
+
test: (pwd) => pwd.length >= minLength
|
|
604
|
+
});
|
|
605
|
+
return requirements;
|
|
606
|
+
}
|
|
607
|
+
function validatePasswordStrength(password, config) {
|
|
550
608
|
if (!password) return false;
|
|
609
|
+
const requirements = createRequirements(config);
|
|
551
610
|
return requirements.every((req) => req.test(password));
|
|
552
611
|
}
|
|
553
|
-
function AuthPasswordStrengthIndicator({
|
|
612
|
+
function AuthPasswordStrengthIndicator({
|
|
613
|
+
password,
|
|
614
|
+
config
|
|
615
|
+
}) {
|
|
616
|
+
const requirements = createRequirements(config);
|
|
554
617
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "insforge-password-strength", children: requirements.map((requirement, index) => {
|
|
555
618
|
const isValid = requirement.test(password);
|
|
556
619
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "insforge-password-requirement", children: [
|
|
@@ -572,14 +635,15 @@ function AuthPasswordField({
|
|
|
572
635
|
label,
|
|
573
636
|
id,
|
|
574
637
|
showStrengthIndicator = false,
|
|
638
|
+
emailAuthConfig,
|
|
575
639
|
forgotPasswordLink,
|
|
576
640
|
value,
|
|
577
641
|
className = "",
|
|
578
642
|
onFocus,
|
|
579
643
|
...props
|
|
580
644
|
}) {
|
|
581
|
-
const [showPassword, setShowPassword] = (0,
|
|
582
|
-
const [showStrength, setShowStrength] = (0,
|
|
645
|
+
const [showPassword, setShowPassword] = (0, import_react4.useState)(false);
|
|
646
|
+
const [showStrength, setShowStrength] = (0, import_react4.useState)(false);
|
|
583
647
|
const handleFocus = (e) => {
|
|
584
648
|
if (showStrengthIndicator) {
|
|
585
649
|
setShowStrength(true);
|
|
@@ -614,7 +678,13 @@ function AuthPasswordField({
|
|
|
614
678
|
}
|
|
615
679
|
)
|
|
616
680
|
] }),
|
|
617
|
-
showStrengthIndicator && showStrength && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
681
|
+
showStrengthIndicator && showStrength && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
682
|
+
AuthPasswordStrengthIndicator,
|
|
683
|
+
{
|
|
684
|
+
password: String(value || ""),
|
|
685
|
+
config: emailAuthConfig
|
|
686
|
+
}
|
|
687
|
+
)
|
|
618
688
|
] });
|
|
619
689
|
}
|
|
620
690
|
|
|
@@ -906,7 +976,7 @@ function AuthOAuthProviders({
|
|
|
906
976
|
}
|
|
907
977
|
|
|
908
978
|
// src/components/auth/AuthVerificationCodeInput.tsx
|
|
909
|
-
var
|
|
979
|
+
var import_react5 = require("react");
|
|
910
980
|
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
911
981
|
function AuthVerificationCodeInput({
|
|
912
982
|
length = 6,
|
|
@@ -915,7 +985,7 @@ function AuthVerificationCodeInput({
|
|
|
915
985
|
onChange,
|
|
916
986
|
disabled = false
|
|
917
987
|
}) {
|
|
918
|
-
const inputRefs = (0,
|
|
988
|
+
const inputRefs = (0, import_react5.useRef)([]);
|
|
919
989
|
const handleChange = (index, digit) => {
|
|
920
990
|
if (digit.length > 1) return;
|
|
921
991
|
if (digit && !/^\d$/.test(digit)) return;
|
|
@@ -999,12 +1069,13 @@ function SignIn({
|
|
|
999
1069
|
}) {
|
|
1000
1070
|
const { signIn, baseUrl } = useInsforge();
|
|
1001
1071
|
const { providers: oauthProviders } = useOAuthProviders();
|
|
1002
|
-
const
|
|
1003
|
-
const [
|
|
1004
|
-
const [
|
|
1005
|
-
const [
|
|
1006
|
-
const [
|
|
1007
|
-
const
|
|
1072
|
+
const { config: emailAuthConfig } = useEmailAuthConfig();
|
|
1073
|
+
const [email, setEmail] = (0, import_react6.useState)("");
|
|
1074
|
+
const [password, setPassword] = (0, import_react6.useState)("");
|
|
1075
|
+
const [error, setError] = (0, import_react6.useState)("");
|
|
1076
|
+
const [loading, setLoading] = (0, import_react6.useState)(false);
|
|
1077
|
+
const [oauthLoading, setOauthLoading] = (0, import_react6.useState)(null);
|
|
1078
|
+
const insforge = (0, import_react6.useState)(() => (0, import_sdk4.createClient)({ baseUrl }))[0];
|
|
1008
1079
|
async function handleSubmit(e) {
|
|
1009
1080
|
e.preventDefault();
|
|
1010
1081
|
setLoading(true);
|
|
@@ -1033,7 +1104,6 @@ function SignIn({
|
|
|
1033
1104
|
provider,
|
|
1034
1105
|
redirectTo
|
|
1035
1106
|
});
|
|
1036
|
-
console.log("handleOAuth result", result);
|
|
1037
1107
|
} catch (err) {
|
|
1038
1108
|
const errorMessage = err.message || `${provider} sign in failed`;
|
|
1039
1109
|
setError(errorMessage);
|
|
@@ -1067,7 +1137,15 @@ function SignIn({
|
|
|
1067
1137
|
value: password,
|
|
1068
1138
|
onChange: (e) => setPassword(e.target.value),
|
|
1069
1139
|
required: true,
|
|
1070
|
-
autoComplete: "current-password"
|
|
1140
|
+
autoComplete: "current-password",
|
|
1141
|
+
emailAuthConfig: emailAuthConfig || {
|
|
1142
|
+
requireEmailVerification: false,
|
|
1143
|
+
passwordMinLength: 6,
|
|
1144
|
+
requireNumber: false,
|
|
1145
|
+
requireLowercase: false,
|
|
1146
|
+
requireUppercase: false,
|
|
1147
|
+
requireSpecialChar: false
|
|
1148
|
+
}
|
|
1071
1149
|
}
|
|
1072
1150
|
),
|
|
1073
1151
|
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
@@ -1097,8 +1175,8 @@ function SignIn({
|
|
|
1097
1175
|
}
|
|
1098
1176
|
|
|
1099
1177
|
// src/components/SignUp.tsx
|
|
1100
|
-
var
|
|
1101
|
-
var
|
|
1178
|
+
var import_react7 = require("react");
|
|
1179
|
+
var import_sdk5 = require("@insforge/sdk");
|
|
1102
1180
|
var import_jsx_runtime17 = require("react/jsx-runtime");
|
|
1103
1181
|
function SignUp({
|
|
1104
1182
|
afterSignUpUrl = "/",
|
|
@@ -1123,17 +1201,18 @@ function SignUp({
|
|
|
1123
1201
|
}) {
|
|
1124
1202
|
const { signUp, baseUrl } = useInsforge();
|
|
1125
1203
|
const { providers: oauthProviders } = useOAuthProviders();
|
|
1126
|
-
const
|
|
1127
|
-
const [
|
|
1128
|
-
const [
|
|
1129
|
-
const [
|
|
1130
|
-
const [
|
|
1131
|
-
const
|
|
1204
|
+
const { config: emailAuthConfig } = useEmailAuthConfig();
|
|
1205
|
+
const [email, setEmail] = (0, import_react7.useState)("");
|
|
1206
|
+
const [password, setPassword] = (0, import_react7.useState)("");
|
|
1207
|
+
const [error, setError] = (0, import_react7.useState)("");
|
|
1208
|
+
const [loading, setLoading] = (0, import_react7.useState)(false);
|
|
1209
|
+
const [oauthLoading, setOauthLoading] = (0, import_react7.useState)(null);
|
|
1210
|
+
const insforge = (0, import_react7.useState)(() => (0, import_sdk5.createClient)({ baseUrl }))[0];
|
|
1132
1211
|
async function handleCredentialsSubmit(e) {
|
|
1133
1212
|
e.preventDefault();
|
|
1134
1213
|
setLoading(true);
|
|
1135
1214
|
setError("");
|
|
1136
|
-
if (!validatePasswordStrength(password)) {
|
|
1215
|
+
if (emailAuthConfig && !validatePasswordStrength(password, emailAuthConfig)) {
|
|
1137
1216
|
setError("Password does not meet all requirements");
|
|
1138
1217
|
setLoading(false);
|
|
1139
1218
|
return;
|
|
@@ -1198,9 +1277,17 @@ function SignUp({
|
|
|
1198
1277
|
value: password,
|
|
1199
1278
|
onChange: (e) => setPassword(e.target.value),
|
|
1200
1279
|
required: true,
|
|
1201
|
-
minLength: 8,
|
|
1280
|
+
minLength: emailAuthConfig?.passwordMinLength ?? 8,
|
|
1202
1281
|
autoComplete: "new-password",
|
|
1203
|
-
showStrengthIndicator: true
|
|
1282
|
+
showStrengthIndicator: true,
|
|
1283
|
+
emailAuthConfig: emailAuthConfig || {
|
|
1284
|
+
requireEmailVerification: false,
|
|
1285
|
+
passwordMinLength: 6,
|
|
1286
|
+
requireNumber: false,
|
|
1287
|
+
requireLowercase: false,
|
|
1288
|
+
requireUppercase: false,
|
|
1289
|
+
requireSpecialChar: false
|
|
1290
|
+
}
|
|
1204
1291
|
}
|
|
1205
1292
|
),
|
|
1206
1293
|
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
@@ -1237,7 +1324,7 @@ function SignUp({
|
|
|
1237
1324
|
}
|
|
1238
1325
|
|
|
1239
1326
|
// src/components/UserButton.tsx
|
|
1240
|
-
var
|
|
1327
|
+
var import_react8 = require("react");
|
|
1241
1328
|
var import_lucide_react6 = require("lucide-react");
|
|
1242
1329
|
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
1243
1330
|
function UserButton({
|
|
@@ -1246,9 +1333,9 @@ function UserButton({
|
|
|
1246
1333
|
appearance = {}
|
|
1247
1334
|
}) {
|
|
1248
1335
|
const { user, signOut } = useInsforge();
|
|
1249
|
-
const [isOpen, setIsOpen] = (0,
|
|
1250
|
-
const dropdownRef = (0,
|
|
1251
|
-
(0,
|
|
1336
|
+
const [isOpen, setIsOpen] = (0, import_react8.useState)(false);
|
|
1337
|
+
const dropdownRef = (0, import_react8.useRef)(null);
|
|
1338
|
+
(0, import_react8.useEffect)(() => {
|
|
1252
1339
|
function handleClickOutside(event) {
|
|
1253
1340
|
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
|
1254
1341
|
setIsOpen(false);
|
|
@@ -1313,7 +1400,7 @@ function SignedOut({ children }) {
|
|
|
1313
1400
|
}
|
|
1314
1401
|
|
|
1315
1402
|
// src/components/Protect.tsx
|
|
1316
|
-
var
|
|
1403
|
+
var import_react9 = require("react");
|
|
1317
1404
|
var import_navigation = require("next/navigation");
|
|
1318
1405
|
var import_jsx_runtime21 = require("react/jsx-runtime");
|
|
1319
1406
|
function Protect({
|
|
@@ -1324,7 +1411,7 @@ function Protect({
|
|
|
1324
1411
|
}) {
|
|
1325
1412
|
const { isSignedIn, isLoaded, user } = useInsforge();
|
|
1326
1413
|
const router = (0, import_navigation.useRouter)();
|
|
1327
|
-
(0,
|
|
1414
|
+
(0, import_react9.useEffect)(() => {
|
|
1328
1415
|
if (isLoaded && !isSignedIn) {
|
|
1329
1416
|
router.push(redirectTo);
|
|
1330
1417
|
} else if (isLoaded && isSignedIn && condition && user) {
|
|
@@ -1372,7 +1459,6 @@ function Protect({
|
|
|
1372
1459
|
isProviderSupported,
|
|
1373
1460
|
useAuth,
|
|
1374
1461
|
useInsforge,
|
|
1375
|
-
useOAuthProviders,
|
|
1376
1462
|
useSession,
|
|
1377
1463
|
useUser,
|
|
1378
1464
|
validatePasswordStrength
|