@insforge/nextjs 0.4.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/index.js ADDED
@@ -0,0 +1,1086 @@
1
+ "use client";
2
+ "use strict";
3
+ "use client";
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __export = (target, all) => {
11
+ for (var name in all)
12
+ __defProp(target, name, { get: all[name], enumerable: true });
13
+ };
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
+ mod
29
+ ));
30
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
31
+
32
+ // src/index.ts
33
+ var src_exports = {};
34
+ __export(src_exports, {
35
+ AuthProvider: () => AuthProvider,
36
+ InsforgeConfigProvider: () => InsforgeConfigProvider,
37
+ Protect: () => Protect,
38
+ SignIn: () => SignIn,
39
+ SignUp: () => SignUp,
40
+ SignedIn: () => SignedIn,
41
+ SignedOut: () => SignedOut,
42
+ UserButton: () => UserButton,
43
+ useAuth: () => useAuth,
44
+ useInsforgeConfig: () => useInsforgeConfig,
45
+ useOAuthProviders: () => useOAuthProviders,
46
+ useSession: () => useSession,
47
+ useUser: () => useUser
48
+ });
49
+ module.exports = __toCommonJS(src_exports);
50
+
51
+ // src/provider/AuthProvider.tsx
52
+ var import_react = require("react");
53
+ var import_sdk = require("@insforge/sdk");
54
+ var import_jsx_runtime = require("react/jsx-runtime");
55
+ var AuthContext = (0, import_react.createContext)(void 0);
56
+ function getTokenFromSDK() {
57
+ if (typeof window === "undefined") return null;
58
+ try {
59
+ const token = localStorage.getItem("insforge-auth-token");
60
+ return token;
61
+ } catch (error) {
62
+ return null;
63
+ }
64
+ }
65
+ async function syncTokenToCookie(token) {
66
+ try {
67
+ const response = await fetch("/api/auth", {
68
+ method: "POST",
69
+ headers: {
70
+ "Content-Type": "application/json"
71
+ },
72
+ body: JSON.stringify({
73
+ action: "sync-token",
74
+ token
75
+ })
76
+ });
77
+ if (!response.ok) {
78
+ return false;
79
+ }
80
+ return true;
81
+ } catch (error) {
82
+ return false;
83
+ }
84
+ }
85
+ function AuthProvider({ children, baseUrl, onAuthChange }) {
86
+ const [user, setUser] = (0, import_react.useState)(null);
87
+ const [session, setSession] = (0, import_react.useState)(null);
88
+ const [isLoaded, setIsLoaded] = (0, import_react.useState)(false);
89
+ const refreshIntervalRef = (0, import_react.useRef)();
90
+ const insforge = (0, import_react.useRef)((0, import_sdk.createClient)({ baseUrl })).current;
91
+ const loadAuthState = (0, import_react.useCallback)(async () => {
92
+ try {
93
+ const token = getTokenFromSDK();
94
+ if (!token) {
95
+ setUser(null);
96
+ setSession(null);
97
+ if (onAuthChange) {
98
+ onAuthChange(null);
99
+ }
100
+ setIsLoaded(true);
101
+ return;
102
+ }
103
+ try {
104
+ await syncTokenToCookie(token);
105
+ } catch (error) {
106
+ }
107
+ const userResult = await insforge.auth.getCurrentUser();
108
+ if (userResult.data) {
109
+ const userData = {
110
+ id: userResult.data.user.id,
111
+ email: userResult.data.user.email,
112
+ createdAt: userResult.data.user.createdAt || (/* @__PURE__ */ new Date()).toISOString(),
113
+ updatedAt: userResult.data.user.updatedAt || (/* @__PURE__ */ new Date()).toISOString(),
114
+ ...userResult.data.profile
115
+ // Add profile data if available
116
+ };
117
+ setUser(userData);
118
+ setSession({
119
+ userId: userResult.data.user.id,
120
+ token,
121
+ expiresAt: "",
122
+ // Insforge tokens are long-lived
123
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
124
+ });
125
+ if (onAuthChange) {
126
+ onAuthChange(userData);
127
+ }
128
+ } else {
129
+ localStorage.removeItem("insforge-auth-token");
130
+ try {
131
+ await fetch("/api/auth", { method: "DELETE" });
132
+ } catch (error) {
133
+ }
134
+ setUser(null);
135
+ setSession(null);
136
+ if (onAuthChange) {
137
+ onAuthChange(null);
138
+ }
139
+ }
140
+ } catch (error) {
141
+ localStorage.removeItem("insforge-auth-token");
142
+ try {
143
+ await fetch("/api/auth", { method: "DELETE" });
144
+ } catch (error2) {
145
+ }
146
+ setUser(null);
147
+ setSession(null);
148
+ if (onAuthChange) {
149
+ onAuthChange(null);
150
+ }
151
+ } finally {
152
+ setIsLoaded(true);
153
+ }
154
+ }, [insforge, onAuthChange]);
155
+ (0, import_react.useEffect)(() => {
156
+ loadAuthState();
157
+ return () => {
158
+ if (refreshIntervalRef.current) {
159
+ clearInterval(refreshIntervalRef.current);
160
+ }
161
+ };
162
+ }, []);
163
+ const signIn = (0, import_react.useCallback)(
164
+ async (email, password) => {
165
+ const sdkResult = await insforge.auth.signInWithPassword({ email, password });
166
+ if (sdkResult.data) {
167
+ const userData = {
168
+ id: sdkResult.data.user.id,
169
+ email: sdkResult.data.user.email,
170
+ name: sdkResult.data.user.name || void 0,
171
+ createdAt: sdkResult.data.user.createdAt,
172
+ updatedAt: sdkResult.data.user.updatedAt
173
+ };
174
+ const sessionData = {
175
+ userId: sdkResult.data.user.id,
176
+ token: sdkResult.data.accessToken,
177
+ expiresAt: "",
178
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
179
+ };
180
+ setUser(userData);
181
+ setSession(sessionData);
182
+ if (onAuthChange) {
183
+ onAuthChange(userData);
184
+ }
185
+ try {
186
+ await syncTokenToCookie(sdkResult.data.accessToken);
187
+ } catch (error) {
188
+ }
189
+ }
190
+ },
191
+ [baseUrl, onAuthChange, insforge]
192
+ );
193
+ const signUp = (0, import_react.useCallback)(
194
+ async (email, password) => {
195
+ const sdkResult = await insforge.auth.signUp({ email, password });
196
+ if (sdkResult.data) {
197
+ const userData = {
198
+ id: sdkResult.data.user.id,
199
+ email: sdkResult.data.user.email,
200
+ name: sdkResult.data.user.name || void 0,
201
+ createdAt: sdkResult.data.user.createdAt,
202
+ updatedAt: sdkResult.data.user.updatedAt
203
+ };
204
+ const sessionData = {
205
+ userId: sdkResult.data.user.id,
206
+ token: sdkResult.data.accessToken,
207
+ expiresAt: "",
208
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
209
+ };
210
+ setUser(userData);
211
+ setSession(sessionData);
212
+ if (onAuthChange) {
213
+ onAuthChange(userData);
214
+ }
215
+ try {
216
+ await syncTokenToCookie(sdkResult.data.accessToken);
217
+ } catch (error) {
218
+ }
219
+ }
220
+ },
221
+ [baseUrl, onAuthChange, insforge]
222
+ );
223
+ const signOut = (0, import_react.useCallback)(async () => {
224
+ await insforge.auth.signOut();
225
+ await fetch("/api/auth", { method: "DELETE" }).catch(() => {
226
+ });
227
+ if (refreshIntervalRef.current) {
228
+ clearInterval(refreshIntervalRef.current);
229
+ }
230
+ setUser(null);
231
+ setSession(null);
232
+ if (onAuthChange) {
233
+ onAuthChange(null);
234
+ }
235
+ }, [baseUrl, onAuthChange, insforge]);
236
+ const updateUser = (0, import_react.useCallback)(
237
+ async (data) => {
238
+ if (!user) throw new Error("No user signed in");
239
+ const result = await insforge.auth.setProfile(data);
240
+ if (result.data) {
241
+ const updatedUser = { ...user, ...result.data };
242
+ setUser(updatedUser);
243
+ if (onAuthChange) {
244
+ onAuthChange(updatedUser);
245
+ }
246
+ }
247
+ },
248
+ [user, onAuthChange, insforge]
249
+ );
250
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
251
+ AuthContext.Provider,
252
+ {
253
+ value: {
254
+ user,
255
+ session,
256
+ isLoaded,
257
+ isSignedIn: !!user,
258
+ signIn,
259
+ signUp,
260
+ signOut,
261
+ updateUser
262
+ },
263
+ children
264
+ }
265
+ );
266
+ }
267
+ function useAuthContext() {
268
+ const context = (0, import_react.useContext)(AuthContext);
269
+ if (!context) {
270
+ throw new Error("useAuthContext must be used within AuthProvider");
271
+ }
272
+ return context;
273
+ }
274
+
275
+ // src/provider/InsforgeConfigProvider.tsx
276
+ var import_react2 = require("react");
277
+ var import_jsx_runtime2 = require("react/jsx-runtime");
278
+ var InsforgeConfigContext = (0, import_react2.createContext)(void 0);
279
+ async function fetchBackendConfig(baseUrl) {
280
+ try {
281
+ const response = await fetch(`${baseUrl}/api/auth/config`);
282
+ if (!response.ok) {
283
+ return [];
284
+ }
285
+ const config = await response.json();
286
+ if (config?.oauth?.providers && Array.isArray(config.oauth.providers)) {
287
+ return config.oauth.providers.filter((p) => p.enabled).map((p) => p.provider);
288
+ }
289
+ return [];
290
+ } catch (error) {
291
+ return [];
292
+ }
293
+ }
294
+ function InsforgeConfigProvider({ children, baseUrl }) {
295
+ const [oauthProviders, setOauthProviders] = (0, import_react2.useState)([]);
296
+ const [isLoaded, setIsLoaded] = (0, import_react2.useState)(false);
297
+ const fetchConfig = async () => {
298
+ const providers = await fetchBackendConfig(baseUrl);
299
+ setOauthProviders(providers);
300
+ setIsLoaded(true);
301
+ };
302
+ (0, import_react2.useEffect)(() => {
303
+ fetchConfig();
304
+ }, [baseUrl]);
305
+ const refetch = async () => {
306
+ setIsLoaded(false);
307
+ await fetchConfig();
308
+ };
309
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
310
+ InsforgeConfigContext.Provider,
311
+ {
312
+ value: {
313
+ oauthProviders,
314
+ isLoaded,
315
+ refetch
316
+ },
317
+ children
318
+ }
319
+ );
320
+ }
321
+ function useInsforgeConfig() {
322
+ const context = (0, import_react2.useContext)(InsforgeConfigContext);
323
+ if (!context) {
324
+ throw new Error("useInsforgeConfig must be used within InsforgeConfigProvider");
325
+ }
326
+ return context;
327
+ }
328
+
329
+ // src/hooks/useAuth.ts
330
+ function useAuth() {
331
+ return useAuthContext();
332
+ }
333
+
334
+ // src/hooks/useUser.ts
335
+ function useUser() {
336
+ const { user, isLoaded } = useAuthContext();
337
+ return { user, isLoaded };
338
+ }
339
+
340
+ // src/hooks/useSession.ts
341
+ function useSession() {
342
+ const { session, isLoaded, isSignedIn } = useAuthContext();
343
+ return { session, isLoaded, isSignedIn };
344
+ }
345
+
346
+ // src/hooks/useOAuthProviders.ts
347
+ function useOAuthProviders() {
348
+ const { oauthProviders } = useInsforgeConfig();
349
+ return oauthProviders;
350
+ }
351
+
352
+ // src/components/SignIn.tsx
353
+ var import_react3 = require("react");
354
+ var import_link = __toESM(require("next/link"));
355
+ var import_sdk2 = require("@insforge/sdk");
356
+ var import_lucide_react2 = require("lucide-react");
357
+
358
+ // src/components/OAuthButton.tsx
359
+ var import_lucide_react = require("lucide-react");
360
+ var import_jsx_runtime3 = require("react/jsx-runtime");
361
+ var providerConfig = {
362
+ google: {
363
+ name: "Google",
364
+ svg: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("svg", { width: "18", height: "18", viewBox: "0 0 18 18", fill: "none", children: [
365
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
366
+ "path",
367
+ {
368
+ d: "M17.64 9.2c0-.637-.057-1.251-.164-1.84H9v3.481h4.844c-.209 1.125-.843 2.078-1.796 2.717v2.258h2.908c1.702-1.567 2.684-3.874 2.684-6.615z",
369
+ fill: "#4285F4"
370
+ }
371
+ ),
372
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
373
+ "path",
374
+ {
375
+ d: "M9 18c2.43 0 4.467-.806 5.956-2.184l-2.908-2.258c-.806.54-1.837.86-3.048.86-2.344 0-4.328-1.584-5.036-3.711H.957v2.332C2.438 15.983 5.482 18 9 18z",
376
+ fill: "#34A853"
377
+ }
378
+ ),
379
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
380
+ "path",
381
+ {
382
+ d: "M3.964 10.707c-.18-.54-.282-1.117-.282-1.707 0-.593.102-1.17.282-1.709V4.958H.957C.347 6.173 0 7.548 0 9c0 1.452.348 2.827.957 4.042l3.007-2.335z",
383
+ fill: "#FBBC05"
384
+ }
385
+ ),
386
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
387
+ "path",
388
+ {
389
+ d: "M9 3.58c1.321 0 2.508.454 3.44 1.345l2.582-2.58C13.463.891 11.426 0 9 0 5.482 0 2.438 2.017.957 4.958L3.964 7.29C4.672 5.163 6.656 3.58 9 3.58z",
390
+ fill: "#EA4335"
391
+ }
392
+ )
393
+ ] }),
394
+ className: "insforge-oauth-google"
395
+ },
396
+ github: {
397
+ name: "GitHub",
398
+ svg: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("svg", { width: "18", height: "18", viewBox: "0 0 16 16", fill: "currentColor", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z" }) }),
399
+ className: "insforge-oauth-github"
400
+ }
401
+ };
402
+ function OAuthButton({ provider, onClick, disabled, loading }) {
403
+ const config = providerConfig[provider];
404
+ if (!config) {
405
+ return null;
406
+ }
407
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
408
+ "button",
409
+ {
410
+ type: "button",
411
+ onClick: () => onClick(provider),
412
+ className: "insforge-oauth-btn",
413
+ disabled: disabled || loading,
414
+ "data-loading": loading || void 0,
415
+ children: [
416
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_lucide_react.Loader2, { className: "insforge-oauth-loader", size: 18 }),
417
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "insforge-oauth-icon", children: config.svg }),
418
+ loading ? "Authenticating..." : `Continue with ${config.name}`
419
+ ]
420
+ }
421
+ );
422
+ }
423
+
424
+ // src/components/SignIn.tsx
425
+ var import_jsx_runtime4 = require("react/jsx-runtime");
426
+ function SignIn({
427
+ baseUrl,
428
+ afterSignInUrl = "/",
429
+ providers = [],
430
+ appearance = {},
431
+ title = "Welcome Back",
432
+ subtitle = "Login to your account",
433
+ emailLabel = "Email",
434
+ emailPlaceholder = "example@email.com",
435
+ passwordLabel = "Password",
436
+ passwordPlaceholder = "\u2022\u2022\u2022\u2022\u2022\u2022",
437
+ forgotPasswordText = "Forget Password?",
438
+ submitButtonText = "Sign In",
439
+ loadingButtonText = "Signing in...",
440
+ signUpText = "Don't have an account?",
441
+ signUpLinkText = "Sign Up Now",
442
+ signUpUrl = "/sign-up",
443
+ dividerText = "or",
444
+ onSuccess,
445
+ onError
446
+ }) {
447
+ const { signIn } = useAuth();
448
+ const [email, setEmail] = (0, import_react3.useState)("");
449
+ const [password, setPassword] = (0, import_react3.useState)("");
450
+ const [error, setError] = (0, import_react3.useState)("");
451
+ const [loading, setLoading] = (0, import_react3.useState)(false);
452
+ const [showPassword, setShowPassword] = (0, import_react3.useState)(false);
453
+ const [oauthLoading, setOauthLoading] = (0, import_react3.useState)(null);
454
+ const insforge = (0, import_react3.useState)(() => (0, import_sdk2.createClient)({ baseUrl }))[0];
455
+ async function handleSubmit(e) {
456
+ e.preventDefault();
457
+ setLoading(true);
458
+ setError("");
459
+ try {
460
+ await signIn(email, password);
461
+ if (onSuccess) {
462
+ const userResult = await insforge.auth.getCurrentUser();
463
+ if (userResult.data) onSuccess(userResult.data);
464
+ }
465
+ window.location.href = afterSignInUrl;
466
+ } catch (err) {
467
+ const errorMessage = err.message || "Sign in failed";
468
+ setError(errorMessage);
469
+ if (onError) onError(new Error(errorMessage));
470
+ } finally {
471
+ setLoading(false);
472
+ }
473
+ }
474
+ async function handleOAuth(provider) {
475
+ try {
476
+ setOauthLoading(provider);
477
+ const redirectTo = `${window.location.origin}/auth/callback`;
478
+ sessionStorage.setItem("oauth_final_destination", afterSignInUrl || "/");
479
+ const result = await insforge.auth.signInWithOAuth({
480
+ provider,
481
+ redirectTo
482
+ });
483
+ if (result.data?.url) {
484
+ window.location.href = result.data.url;
485
+ }
486
+ } catch (err) {
487
+ const errorMessage = err.message || `${provider} sign in failed`;
488
+ setError(errorMessage);
489
+ if (onError) onError(new Error(errorMessage));
490
+ setOauthLoading(null);
491
+ }
492
+ }
493
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "insforge-auth-container", style: appearance.container, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "insforge-auth-card", style: appearance.form, children: [
494
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "insforge-auth-content", children: [
495
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "insforge-auth-header", children: [
496
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h1", { className: "insforge-auth-title", children: title }),
497
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "insforge-auth-subtitle", children: subtitle })
498
+ ] }),
499
+ error && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "insforge-error-banner", children: [
500
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_lucide_react2.AlertTriangle, { className: "insforge-error-icon" }),
501
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: error })
502
+ ] }),
503
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("form", { onSubmit: handleSubmit, className: "insforge-form", children: [
504
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "insforge-form-group", children: [
505
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("label", { htmlFor: "email", className: "insforge-form-label", children: emailLabel }),
506
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
507
+ "input",
508
+ {
509
+ id: "email",
510
+ type: "email",
511
+ className: "insforge-input",
512
+ placeholder: emailPlaceholder,
513
+ value: email,
514
+ onChange: (e) => setEmail(e.target.value),
515
+ required: true,
516
+ autoComplete: "email"
517
+ }
518
+ )
519
+ ] }),
520
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "insforge-form-group", children: [
521
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "insforge-form-label-row", children: [
522
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
523
+ "label",
524
+ {
525
+ htmlFor: "password",
526
+ className: "insforge-form-label",
527
+ style: { margin: 0 },
528
+ children: passwordLabel
529
+ }
530
+ ),
531
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("a", { href: "#", className: "insforge-form-link", children: forgotPasswordText })
532
+ ] }),
533
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "insforge-input-wrapper", children: [
534
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
535
+ "input",
536
+ {
537
+ id: "password",
538
+ type: showPassword ? "text" : "password",
539
+ className: "insforge-input insforge-input-with-icon",
540
+ placeholder: passwordPlaceholder,
541
+ value: password,
542
+ onChange: (e) => setPassword(e.target.value),
543
+ required: true,
544
+ autoComplete: "current-password"
545
+ }
546
+ ),
547
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
548
+ "button",
549
+ {
550
+ type: "button",
551
+ onClick: () => setShowPassword(!showPassword),
552
+ className: "insforge-input-icon-btn",
553
+ "aria-label": showPassword ? "Hide password" : "Show password",
554
+ children: showPassword ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_lucide_react2.EyeOff, { size: 20 }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_lucide_react2.Eye, { size: 20 })
555
+ }
556
+ )
557
+ ] })
558
+ ] }),
559
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
560
+ "button",
561
+ {
562
+ type: "submit",
563
+ className: "insforge-btn-primary",
564
+ style: appearance.button,
565
+ disabled: loading || oauthLoading !== null,
566
+ "data-loading": loading || void 0,
567
+ children: [
568
+ loading && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_lucide_react2.Loader2, { className: "insforge-btn-loader", size: 20 }),
569
+ loading ? loadingButtonText : submitButtonText
570
+ ]
571
+ }
572
+ )
573
+ ] }),
574
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("p", { className: "insforge-text-center", children: [
575
+ signUpText,
576
+ " ",
577
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("a", { href: signUpUrl, className: "insforge-link-primary", children: signUpLinkText })
578
+ ] }),
579
+ providers.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
580
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "insforge-divider", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "insforge-divider-text", children: dividerText }) }),
581
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "insforge-oauth-container", children: providers.map((provider) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
582
+ OAuthButton,
583
+ {
584
+ provider,
585
+ onClick: handleOAuth,
586
+ disabled: loading || oauthLoading !== null,
587
+ loading: oauthLoading === provider
588
+ },
589
+ provider
590
+ )) })
591
+ ] })
592
+ ] }),
593
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "insforge-branding", children: [
594
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "insforge-branding-text", children: "Powered by" }),
595
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
596
+ import_link.default,
597
+ {
598
+ href: "https://insforge.dev",
599
+ target: "_blank",
600
+ rel: "noopener noreferrer",
601
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
602
+ "svg",
603
+ {
604
+ width: "83",
605
+ height: "20",
606
+ viewBox: "0 0 83 20",
607
+ fill: "none",
608
+ xmlns: "http://www.w3.org/2000/svg",
609
+ children: [
610
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
611
+ "path",
612
+ {
613
+ d: "M2.16783 8.46797C1.9334 8.23325 1.9334 7.85269 2.16783 7.61797L8.11049 1.66797L16.6 1.66797L6.41259 11.868C6.17815 12.1027 5.79807 12.1027 5.56363 11.868L2.16783 8.46797Z",
614
+ fill: "url(#paint0_linear_2976_9475)"
615
+ }
616
+ ),
617
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
618
+ "path",
619
+ {
620
+ d: "M12.8858 6.44922L16.6 10.168V18.668L8.64108 10.6992L12.8858 6.44922Z",
621
+ fill: "url(#paint1_linear_2976_9475)"
622
+ }
623
+ ),
624
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
625
+ "path",
626
+ {
627
+ d: "M67.5439 6.48828C68.2894 6.48828 68.9145 6.67064 69.418 7.03516C69.5229 7.10943 69.6214 7.1907 69.7158 7.27637V6.70703H71.248V14.959C71.248 15.1583 71.2381 15.3485 71.2188 15.5283C71.2042 15.7129 71.1774 15.8925 71.1387 16.0674C71.0225 16.5776 70.7998 16.9957 70.4707 17.3213C70.1415 17.6518 69.7321 17.8972 69.2432 18.0576C68.7592 18.2179 68.2222 18.2988 67.6318 18.2988C67.1962 18.2988 66.7768 18.2308 66.375 18.0947C65.9782 17.9587 65.6202 17.7614 65.3008 17.5039C64.9813 17.2512 64.7199 16.9446 64.5166 16.585L66.1289 15.7832C66.2789 16.0698 66.4888 16.2819 66.7598 16.418C67.0356 16.5589 67.3289 16.6289 67.6387 16.6289C68.0016 16.6289 68.3258 16.5628 68.6113 16.4316C68.8969 16.3053 69.1176 16.116 69.2725 15.8633C69.4321 15.6155 69.5077 15.3047 69.498 14.9307V14.1797C69.4665 14.2037 69.4359 14.229 69.4033 14.252C68.8855 14.6164 68.2441 14.7988 67.4795 14.7988C66.7582 14.7988 66.1281 14.6165 65.5908 14.252C65.0537 13.8875 64.637 13.3915 64.3418 12.7646C64.0467 12.1378 63.8994 11.4307 63.8994 10.6436C63.8994 9.84651 64.0465 9.13673 64.3418 8.51465C64.6419 7.88768 65.0663 7.39481 65.6133 7.03516C66.1601 6.67077 66.8036 6.48836 67.5439 6.48828ZM37.5 6.48828C38.1099 6.48828 38.6496 6.58294 39.1191 6.77246C39.5935 6.96201 39.9762 7.2321 40.2666 7.58203C40.5569 7.93184 40.7359 8.34227 40.8037 8.81348L39.0176 9.13477C38.974 8.79951 38.8218 8.53424 38.5605 8.33984C38.304 8.14547 37.96 8.03605 37.5293 8.01172C37.1178 7.98742 36.7859 8.05051 36.5342 8.20117C36.2825 8.34698 36.1562 8.55398 36.1562 8.82129C36.1563 8.97184 36.208 9.10017 36.3096 9.20703C36.4112 9.31394 36.614 9.42141 36.9189 9.52832C37.2288 9.63524 37.6889 9.76635 38.2988 9.92188C38.9232 10.0823 39.4222 10.2666 39.7949 10.4756C40.1722 10.6796 40.4428 10.9254 40.6074 11.2119C40.7768 11.4987 40.8623 11.8466 40.8623 12.2549C40.8623 13.047 40.574 13.6691 39.998 14.1211C39.4268 14.5731 38.6348 14.7988 37.623 14.7988C36.6551 14.7988 35.8687 14.5799 35.2637 14.1426C34.6587 13.7052 34.2909 13.0908 34.1602 12.2988L35.9463 12.0215C36.0383 12.4102 36.2411 12.7169 36.5557 12.9404C36.8703 13.164 37.2678 13.2754 37.7471 13.2754C38.1681 13.2754 38.4922 13.1926 38.7197 13.0273C38.9521 12.8572 39.0684 12.6266 39.0684 12.335C39.0684 12.1552 39.0245 12.0122 38.9375 11.9053C38.8552 11.7935 38.6713 11.686 38.3857 11.584C38.1001 11.4819 37.6618 11.3528 37.0713 11.1973C36.4131 11.0223 35.8901 10.8359 35.5029 10.6367C35.1158 10.4327 34.8374 10.192 34.668 9.91504C34.4985 9.63801 34.4141 9.30188 34.4141 8.9082C34.4141 8.41746 34.5423 7.98943 34.7988 7.625C35.0553 7.26073 35.4135 6.98146 35.873 6.78711C36.3329 6.58784 36.8755 6.48828 37.5 6.48828ZM53.3047 6.48828C54.0937 6.48828 54.7815 6.66572 55.3672 7.02051C55.9527 7.37528 56.4072 7.86634 56.7314 8.49316C57.0558 9.11525 57.2187 9.83193 57.2188 10.6436C57.2188 11.46 57.0537 12.1817 56.7246 12.8086C56.4003 13.4307 55.9451 13.9196 55.3594 14.2744C54.7737 14.6242 54.0888 14.7988 53.3047 14.7988C52.5205 14.7988 51.8357 14.6214 51.25 14.2666C50.6643 13.9118 50.2091 13.4238 49.8848 12.8018C49.5653 12.1748 49.4053 11.4552 49.4053 10.6436C49.4053 9.81735 49.5703 9.09279 49.8994 8.4707C50.2286 7.8488 50.6859 7.36255 51.2715 7.0127C51.8572 6.66281 52.5351 6.48828 53.3047 6.48828ZM76.7471 6.48828C77.5603 6.48828 78.25 6.68053 78.8164 7.06445C79.3876 7.44351 79.812 7.97991 80.0879 8.6748C80.3638 9.36976 80.4672 10.189 80.3994 11.1318H74.7256C74.7843 11.6972 74.949 12.1516 75.2227 12.4951C75.5711 12.9325 76.0792 13.1513 76.7471 13.1514C77.1779 13.1514 77.5486 13.0567 77.8584 12.8672C78.173 12.6728 78.4146 12.3928 78.584 12.0283L80.3125 12.5537C80.0124 13.2633 79.5473 13.8153 78.918 14.209C78.2936 14.6025 77.6036 14.7988 76.8486 14.7988C76.0549 14.7988 75.358 14.6263 74.7578 14.2812C74.1576 13.9362 73.6875 13.458 73.3486 12.8457C73.0147 12.2334 72.8477 11.5284 72.8477 10.7314C72.8477 9.87126 73.0127 9.12495 73.3418 8.49316C73.671 7.85651 74.1282 7.36263 74.7139 7.0127C75.2995 6.6628 75.9775 6.48832 76.7471 6.48828ZM23.3301 14.5801H21.5801V4.08203H23.3301V14.5801ZM29.6152 6.48047C30.1959 6.48052 30.6753 6.5781 31.0527 6.77246C31.4301 6.96681 31.7305 7.21443 31.9531 7.51562C32.1758 7.81695 32.3398 8.13831 32.4463 8.47852C32.5528 8.81873 32.6213 9.14205 32.6504 9.44824C32.6843 9.74946 32.7012 9.99508 32.7012 10.1846V14.5801H30.9287V10.7891C30.9287 10.5413 30.9118 10.2669 30.8779 9.96582C30.844 9.66449 30.7645 9.37469 30.6387 9.09766C30.5177 8.81592 30.3337 8.58503 30.0869 8.40527C29.8449 8.22551 29.5157 8.13579 29.0996 8.13574C28.8769 8.13574 28.6563 8.17221 28.4385 8.24512C28.2206 8.31802 28.0219 8.4442 27.8428 8.62402C27.6685 8.79899 27.5284 9.04249 27.4219 9.35352C27.3154 9.65965 27.2617 10.0532 27.2617 10.5342V14.5801H25.4902V6.70703H27.0518V7.58301C27.2521 7.34675 27.486 7.14172 27.7559 6.96973C28.2593 6.64409 28.8794 6.48047 29.6152 6.48047ZM48.748 5.83887H44.2021V8.45605H47.876V10.2061H44.2021V14.5801H42.4521V4.08203H48.748V5.83887ZM62.5137 6.67773C62.7606 6.65829 63.001 6.66815 63.2334 6.70703V8.34766C63.001 8.27961 62.7317 8.25695 62.4268 8.28125C62.1267 8.30557 61.8553 8.39134 61.6133 8.53711C61.3715 8.66829 61.1733 8.83606 61.0186 9.04004C60.8686 9.24404 60.7572 9.47701 60.6846 9.73926C60.612 9.99685 60.5752 10.2768 60.5752 10.5781V14.5801H58.8184V6.70703H60.3652V7.96582C60.4243 7.85986 60.4888 7.75824 60.5605 7.66211C60.7251 7.4434 60.9219 7.26302 61.1494 7.12207C61.3429 6.99098 61.5559 6.88926 61.7881 6.81641C62.0251 6.73869 62.267 6.69235 62.5137 6.67773ZM67.8057 8.0625C67.3362 8.06252 66.9485 8.17982 66.6436 8.41309C66.3389 8.64144 66.1139 8.95232 65.9688 9.3457C65.8235 9.7345 65.751 10.1673 65.751 10.6436C65.751 11.1247 65.8215 11.5624 65.9619 11.9561C66.1071 12.3447 66.3269 12.6535 66.6221 12.8818C66.9174 13.1103 67.293 13.2246 67.748 13.2246C68.2174 13.2246 68.5953 13.1171 68.8809 12.9033C69.1711 12.6846 69.3811 12.3808 69.5117 11.9922C69.6473 11.6034 69.7158 11.1539 69.7158 10.6436C69.7158 10.1284 69.6473 9.67886 69.5117 9.29492C69.381 8.90617 69.1753 8.60445 68.8945 8.39062C68.6138 8.17213 68.2508 8.0625 67.8057 8.0625ZM53.3047 8.13574C52.8351 8.13574 52.4475 8.24222 52.1426 8.45605C51.8425 8.66504 51.6198 8.95977 51.4746 9.33887C51.3295 9.71303 51.2568 10.148 51.2568 10.6436C51.2568 11.4066 51.4288 12.0168 51.7725 12.4736C52.121 12.9256 52.6318 13.1514 53.3047 13.1514C54.0017 13.1514 54.5196 12.9177 54.8584 12.4512C55.1971 11.9846 55.3672 11.3822 55.3672 10.6436C55.3672 9.8807 55.1951 9.27324 54.8516 8.82129C54.5079 8.36444 53.9921 8.13575 53.3047 8.13574ZM76.8203 8.02637C76.1039 8.02637 75.5712 8.25013 75.2227 8.69727C74.9987 8.98144 74.8476 9.35094 74.7676 9.80566H78.6221C78.5589 9.29301 78.4236 8.89686 78.2139 8.61719C77.9186 8.22359 77.4543 8.02645 76.8203 8.02637Z",
628
+ fill: "black"
629
+ }
630
+ ),
631
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("defs", { children: [
632
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
633
+ "linearGradient",
634
+ {
635
+ id: "paint0_linear_2976_9475",
636
+ x1: "1.85883",
637
+ y1: "1.92425",
638
+ x2: "24.3072",
639
+ y2: "9.64016",
640
+ gradientUnits: "userSpaceOnUse",
641
+ children: [
642
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("stop", {}),
643
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("stop", { offset: "1", stopOpacity: "0.4" })
644
+ ]
645
+ }
646
+ ),
647
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
648
+ "linearGradient",
649
+ {
650
+ id: "paint1_linear_2976_9475",
651
+ x1: "25.6475",
652
+ y1: "8.65468",
653
+ x2: "10.7901",
654
+ y2: "8.65468",
655
+ gradientUnits: "userSpaceOnUse",
656
+ children: [
657
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("stop", {}),
658
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("stop", { offset: "1", stopOpacity: "0.4" })
659
+ ]
660
+ }
661
+ )
662
+ ] })
663
+ ]
664
+ }
665
+ )
666
+ }
667
+ )
668
+ ] })
669
+ ] }) });
670
+ }
671
+
672
+ // src/components/SignUp.tsx
673
+ var import_react4 = require("react");
674
+ var import_link2 = __toESM(require("next/link"));
675
+ var import_sdk3 = require("@insforge/sdk");
676
+ var import_lucide_react4 = require("lucide-react");
677
+
678
+ // src/components/PasswordStrengthIndicator.tsx
679
+ var import_lucide_react3 = require("lucide-react");
680
+ var import_jsx_runtime5 = require("react/jsx-runtime");
681
+ var requirements = [
682
+ {
683
+ label: "At least 1 Uppercase letter",
684
+ test: (pwd) => /[A-Z]/.test(pwd)
685
+ },
686
+ {
687
+ label: "At least 1 Number",
688
+ test: (pwd) => /\d/.test(pwd)
689
+ },
690
+ {
691
+ label: "Special character (e.g. !?<>@#$%)",
692
+ test: (pwd) => /[!@#$%^&*()_+\-=[\]{};\\|,.<>/?]/.test(pwd)
693
+ },
694
+ {
695
+ label: "8 characters or more",
696
+ test: (pwd) => pwd.length >= 8
697
+ }
698
+ ];
699
+ function validatePasswordStrength(password) {
700
+ if (!password) return false;
701
+ return requirements.every((req) => req.test(password));
702
+ }
703
+ function PasswordStrengthIndicator({ password }) {
704
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "insforge-password-strength", children: requirements.map((requirement, index) => {
705
+ const isValid = requirement.test(password);
706
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "insforge-password-requirement", children: [
707
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
708
+ "div",
709
+ {
710
+ className: `insforge-password-check ${isValid ? "insforge-password-check-valid" : ""}`,
711
+ children: isValid && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react3.Check, { className: "insforge-password-check-icon", size: 12 })
712
+ }
713
+ ),
714
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "insforge-password-requirement-label", children: requirement.label })
715
+ ] }, index);
716
+ }) });
717
+ }
718
+
719
+ // src/components/SignUp.tsx
720
+ var import_jsx_runtime6 = require("react/jsx-runtime");
721
+ function SignUp({
722
+ baseUrl,
723
+ afterSignUpUrl = "/",
724
+ providers = [],
725
+ appearance = {},
726
+ title = "Get Started",
727
+ subtitle = "Create account",
728
+ emailLabel = "Email",
729
+ emailPlaceholder = "example@email.com",
730
+ passwordLabel = "Password",
731
+ passwordPlaceholder = "\u2022\u2022\u2022\u2022\u2022\u2022",
732
+ submitButtonText = "Sign Up",
733
+ loadingButtonText = "Creating account...",
734
+ signInText = "Already have an account?",
735
+ signInLinkText = "Login Now",
736
+ signInUrl = "/sign-in",
737
+ dividerText = "or",
738
+ onSuccess,
739
+ onError
740
+ }) {
741
+ const { signUp } = useAuth();
742
+ const [email, setEmail] = (0, import_react4.useState)("");
743
+ const [password, setPassword] = (0, import_react4.useState)("");
744
+ const [error, setError] = (0, import_react4.useState)("");
745
+ const [loading, setLoading] = (0, import_react4.useState)(false);
746
+ const [showPassword, setShowPassword] = (0, import_react4.useState)(false);
747
+ const [oauthLoading, setOauthLoading] = (0, import_react4.useState)(null);
748
+ const [showPasswordStrength, setShowPasswordStrength] = (0, import_react4.useState)(false);
749
+ const insforge = (0, import_react4.useState)(() => (0, import_sdk3.createClient)({ baseUrl }))[0];
750
+ async function handleSubmit(e) {
751
+ e.preventDefault();
752
+ setLoading(true);
753
+ setError("");
754
+ if (!validatePasswordStrength(password)) {
755
+ setError("Password does not meet all requirements");
756
+ setLoading(false);
757
+ return;
758
+ }
759
+ try {
760
+ await signUp(email, password);
761
+ if (onSuccess) {
762
+ const userResult = await insforge.auth.getCurrentUser();
763
+ if (userResult.data) onSuccess(userResult.data);
764
+ }
765
+ window.location.href = afterSignUpUrl;
766
+ } catch (err) {
767
+ const errorMessage = err.message || "Sign up failed";
768
+ setError(errorMessage);
769
+ if (onError) onError(new Error(errorMessage));
770
+ } finally {
771
+ setLoading(false);
772
+ }
773
+ }
774
+ async function handleOAuth(provider) {
775
+ try {
776
+ setOauthLoading(provider);
777
+ const redirectTo = `${window.location.origin}/auth/callback`;
778
+ sessionStorage.setItem("oauth_final_destination", afterSignUpUrl || "/");
779
+ const result = await insforge.auth.signInWithOAuth({
780
+ provider,
781
+ redirectTo
782
+ });
783
+ if (result.data?.url) {
784
+ window.location.href = result.data.url;
785
+ }
786
+ } catch (err) {
787
+ const errorMessage = err.message || `${provider} sign up failed`;
788
+ setError(errorMessage);
789
+ if (onError) onError(new Error(errorMessage));
790
+ setOauthLoading(null);
791
+ }
792
+ }
793
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "insforge-auth-container", style: appearance.container, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "insforge-auth-card", style: appearance.form, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "insforge-auth-content", children: [
794
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "insforge-auth-header", children: [
795
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("h1", { className: "insforge-auth-title", children: title }),
796
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "insforge-auth-subtitle", children: subtitle })
797
+ ] }),
798
+ error && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "insforge-error-banner", children: [
799
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react4.AlertTriangle, { className: "insforge-error-icon" }),
800
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: error })
801
+ ] }),
802
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("form", { onSubmit: handleSubmit, className: "insforge-form", children: [
803
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "insforge-form-group", children: [
804
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("label", { htmlFor: "email", className: "insforge-form-label", children: emailLabel }),
805
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
806
+ "input",
807
+ {
808
+ id: "email",
809
+ type: "email",
810
+ className: "insforge-input",
811
+ placeholder: emailPlaceholder,
812
+ value: email,
813
+ onChange: (e) => setEmail(e.target.value),
814
+ required: true,
815
+ autoComplete: "email"
816
+ }
817
+ )
818
+ ] }),
819
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "insforge-form-group", children: [
820
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("label", { htmlFor: "password", className: "insforge-form-label", children: passwordLabel }),
821
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "insforge-input-wrapper", children: [
822
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
823
+ "input",
824
+ {
825
+ id: "password",
826
+ type: showPassword ? "text" : "password",
827
+ className: "insforge-input insforge-input-with-icon",
828
+ placeholder: passwordPlaceholder,
829
+ value: password,
830
+ onChange: (e) => setPassword(e.target.value),
831
+ onFocus: () => setShowPasswordStrength(true),
832
+ required: true,
833
+ minLength: 8,
834
+ autoComplete: "new-password"
835
+ }
836
+ ),
837
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
838
+ "button",
839
+ {
840
+ type: "button",
841
+ onClick: () => setShowPassword(!showPassword),
842
+ className: "insforge-input-icon-btn",
843
+ "aria-label": showPassword ? "Hide password" : "Show password",
844
+ children: showPassword ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react4.EyeOff, { size: 20 }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react4.Eye, { size: 20 })
845
+ }
846
+ )
847
+ ] }),
848
+ showPasswordStrength && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(PasswordStrengthIndicator, { password })
849
+ ] }),
850
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
851
+ "button",
852
+ {
853
+ type: "submit",
854
+ className: "insforge-btn-primary",
855
+ style: appearance.button,
856
+ disabled: loading || oauthLoading !== null,
857
+ "data-loading": loading || void 0,
858
+ children: [
859
+ loading && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react4.Loader2, { className: "insforge-btn-loader", size: 20 }),
860
+ loading ? loadingButtonText : submitButtonText
861
+ ]
862
+ }
863
+ )
864
+ ] }),
865
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("p", { className: "insforge-text-center", children: [
866
+ signInText,
867
+ " ",
868
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("a", { href: signInUrl, className: "insforge-link-primary", children: signInLinkText })
869
+ ] }),
870
+ providers.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
871
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "insforge-divider", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "insforge-divider-text", children: dividerText }) }),
872
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "insforge-oauth-container", children: providers.map((provider) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
873
+ OAuthButton,
874
+ {
875
+ provider,
876
+ onClick: handleOAuth,
877
+ disabled: loading || oauthLoading !== null,
878
+ loading: oauthLoading === provider
879
+ },
880
+ provider
881
+ )) })
882
+ ] }),
883
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "insforge-branding", children: [
884
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "insforge-branding-text", children: "Powered by" }),
885
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
886
+ import_link2.default,
887
+ {
888
+ href: "https://insforge.dev",
889
+ target: "_blank",
890
+ rel: "noopener noreferrer",
891
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
892
+ "svg",
893
+ {
894
+ width: "83",
895
+ height: "20",
896
+ viewBox: "0 0 83 20",
897
+ fill: "none",
898
+ xmlns: "http://www.w3.org/2000/svg",
899
+ children: [
900
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
901
+ "path",
902
+ {
903
+ d: "M2.16783 8.46797C1.9334 8.23325 1.9334 7.85269 2.16783 7.61797L8.11049 1.66797L16.6 1.66797L6.41259 11.868C6.17815 12.1027 5.79807 12.1027 5.56363 11.868L2.16783 8.46797Z",
904
+ fill: "url(#paint0_linear_2976_9475)"
905
+ }
906
+ ),
907
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
908
+ "path",
909
+ {
910
+ d: "M12.8858 6.44922L16.6 10.168V18.668L8.64108 10.6992L12.8858 6.44922Z",
911
+ fill: "url(#paint1_linear_2976_9475)"
912
+ }
913
+ ),
914
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
915
+ "path",
916
+ {
917
+ d: "M67.5439 6.48828C68.2894 6.48828 68.9145 6.67064 69.418 7.03516C69.5229 7.10943 69.6214 7.1907 69.7158 7.27637V6.70703H71.248V14.959C71.248 15.1583 71.2381 15.3485 71.2188 15.5283C71.2042 15.7129 71.1774 15.8925 71.1387 16.0674C71.0225 16.5776 70.7998 16.9957 70.4707 17.3213C70.1415 17.6518 69.7321 17.8972 69.2432 18.0576C68.7592 18.2179 68.2222 18.2988 67.6318 18.2988C67.1962 18.2988 66.7768 18.2308 66.375 18.0947C65.9782 17.9587 65.6202 17.7614 65.3008 17.5039C64.9813 17.2512 64.7199 16.9446 64.5166 16.585L66.1289 15.7832C66.2789 16.0698 66.4888 16.2819 66.7598 16.418C67.0356 16.5589 67.3289 16.6289 67.6387 16.6289C68.0016 16.6289 68.3258 16.5628 68.6113 16.4316C68.8969 16.3053 69.1176 16.116 69.2725 15.8633C69.4321 15.6155 69.5077 15.3047 69.498 14.9307V14.1797C69.4665 14.2037 69.4359 14.229 69.4033 14.252C68.8855 14.6164 68.2441 14.7988 67.4795 14.7988C66.7582 14.7988 66.1281 14.6165 65.5908 14.252C65.0537 13.8875 64.637 13.3915 64.3418 12.7646C64.0467 12.1378 63.8994 11.4307 63.8994 10.6436C63.8994 9.84651 64.0465 9.13673 64.3418 8.51465C64.6419 7.88768 65.0663 7.39481 65.6133 7.03516C66.1601 6.67077 66.8036 6.48836 67.5439 6.48828ZM37.5 6.48828C38.1099 6.48828 38.6496 6.58294 39.1191 6.77246C39.5935 6.96201 39.9762 7.2321 40.2666 7.58203C40.5569 7.93184 40.7359 8.34227 40.8037 8.81348L39.0176 9.13477C38.974 8.79951 38.8218 8.53424 38.5605 8.33984C38.304 8.14547 37.96 8.03605 37.5293 8.01172C37.1178 7.98742 36.7859 8.05051 36.5342 8.20117C36.2825 8.34698 36.1562 8.55398 36.1562 8.82129C36.1563 8.97184 36.208 9.10017 36.3096 9.20703C36.4112 9.31394 36.614 9.42141 36.9189 9.52832C37.2288 9.63524 37.6889 9.76635 38.2988 9.92188C38.9232 10.0823 39.4222 10.2666 39.7949 10.4756C40.1722 10.6796 40.4428 10.9254 40.6074 11.2119C40.7768 11.4987 40.8623 11.8466 40.8623 12.2549C40.8623 13.047 40.574 13.6691 39.998 14.1211C39.4268 14.5731 38.6348 14.7988 37.623 14.7988C36.6551 14.7988 35.8687 14.5799 35.2637 14.1426C34.6587 13.7052 34.2909 13.0908 34.1602 12.2988L35.9463 12.0215C36.0383 12.4102 36.2411 12.7169 36.5557 12.9404C36.8703 13.164 37.2678 13.2754 37.7471 13.2754C38.1681 13.2754 38.4922 13.1926 38.7197 13.0273C38.9521 12.8572 39.0684 12.6266 39.0684 12.335C39.0684 12.1552 39.0245 12.0122 38.9375 11.9053C38.8552 11.7935 38.6713 11.686 38.3857 11.584C38.1001 11.4819 37.6618 11.3528 37.0713 11.1973C36.4131 11.0223 35.8901 10.8359 35.5029 10.6367C35.1158 10.4327 34.8374 10.192 34.668 9.91504C34.4985 9.63801 34.4141 9.30188 34.4141 8.9082C34.4141 8.41746 34.5423 7.98943 34.7988 7.625C35.0553 7.26073 35.4135 6.98146 35.873 6.78711C36.3329 6.58784 36.8755 6.48828 37.5 6.48828ZM53.3047 6.48828C54.0937 6.48828 54.7815 6.66572 55.3672 7.02051C55.9527 7.37528 56.4072 7.86634 56.7314 8.49316C57.0558 9.11525 57.2187 9.83193 57.2188 10.6436C57.2188 11.46 57.0537 12.1817 56.7246 12.8086C56.4003 13.4307 55.9451 13.9196 55.3594 14.2744C54.7737 14.6242 54.0888 14.7988 53.3047 14.7988C52.5205 14.7988 51.8357 14.6214 51.25 14.2666C50.6643 13.9118 50.2091 13.4238 49.8848 12.8018C49.5653 12.1748 49.4053 11.4552 49.4053 10.6436C49.4053 9.81735 49.5703 9.09279 49.8994 8.4707C50.2286 7.8488 50.6859 7.36255 51.2715 7.0127C51.8572 6.66281 52.5351 6.48828 53.3047 6.48828ZM76.7471 6.48828C77.5603 6.48828 78.25 6.68053 78.8164 7.06445C79.3876 7.44351 79.812 7.97991 80.0879 8.6748C80.3638 9.36976 80.4672 10.189 80.3994 11.1318H74.7256C74.7843 11.6972 74.949 12.1516 75.2227 12.4951C75.5711 12.9325 76.0792 13.1513 76.7471 13.1514C77.1779 13.1514 77.5486 13.0567 77.8584 12.8672C78.173 12.6728 78.4146 12.3928 78.584 12.0283L80.3125 12.5537C80.0124 13.2633 79.5473 13.8153 78.918 14.209C78.2936 14.6025 77.6036 14.7988 76.8486 14.7988C76.0549 14.7988 75.358 14.6263 74.7578 14.2812C74.1576 13.9362 73.6875 13.458 73.3486 12.8457C73.0147 12.2334 72.8477 11.5284 72.8477 10.7314C72.8477 9.87126 73.0127 9.12495 73.3418 8.49316C73.671 7.85651 74.1282 7.36263 74.7139 7.0127C75.2995 6.6628 75.9775 6.48832 76.7471 6.48828ZM23.3301 14.5801H21.5801V4.08203H23.3301V14.5801ZM29.6152 6.48047C30.1959 6.48052 30.6753 6.5781 31.0527 6.77246C31.4301 6.96681 31.7305 7.21443 31.9531 7.51562C32.1758 7.81695 32.3398 8.13831 32.4463 8.47852C32.5528 8.81873 32.6213 9.14205 32.6504 9.44824C32.6843 9.74946 32.7012 9.99508 32.7012 10.1846V14.5801H30.9287V10.7891C30.9287 10.5413 30.9118 10.2669 30.8779 9.96582C30.844 9.66449 30.7645 9.37469 30.6387 9.09766C30.5177 8.81592 30.3337 8.58503 30.0869 8.40527C29.8449 8.22551 29.5157 8.13579 29.0996 8.13574C28.8769 8.13574 28.6563 8.17221 28.4385 8.24512C28.2206 8.31802 28.0219 8.4442 27.8428 8.62402C27.6685 8.79899 27.5284 9.04249 27.4219 9.35352C27.3154 9.65965 27.2617 10.0532 27.2617 10.5342V14.5801H25.4902V6.70703H27.0518V7.58301C27.2521 7.34675 27.486 7.14172 27.7559 6.96973C28.2593 6.64409 28.8794 6.48047 29.6152 6.48047ZM48.748 5.83887H44.2021V8.45605H47.876V10.2061H44.2021V14.5801H42.4521V4.08203H48.748V5.83887ZM62.5137 6.67773C62.7606 6.65829 63.001 6.66815 63.2334 6.70703V8.34766C63.001 8.27961 62.7317 8.25695 62.4268 8.28125C62.1267 8.30557 61.8553 8.39134 61.6133 8.53711C61.3715 8.66829 61.1733 8.83606 61.0186 9.04004C60.8686 9.24404 60.7572 9.47701 60.6846 9.73926C60.612 9.99685 60.5752 10.2768 60.5752 10.5781V14.5801H58.8184V6.70703H60.3652V7.96582C60.4243 7.85986 60.4888 7.75824 60.5605 7.66211C60.7251 7.4434 60.9219 7.26302 61.1494 7.12207C61.3429 6.99098 61.5559 6.88926 61.7881 6.81641C62.0251 6.73869 62.267 6.69235 62.5137 6.67773ZM67.8057 8.0625C67.3362 8.06252 66.9485 8.17982 66.6436 8.41309C66.3389 8.64144 66.1139 8.95232 65.9688 9.3457C65.8235 9.7345 65.751 10.1673 65.751 10.6436C65.751 11.1247 65.8215 11.5624 65.9619 11.9561C66.1071 12.3447 66.3269 12.6535 66.6221 12.8818C66.9174 13.1103 67.293 13.2246 67.748 13.2246C68.2174 13.2246 68.5953 13.1171 68.8809 12.9033C69.1711 12.6846 69.3811 12.3808 69.5117 11.9922C69.6473 11.6034 69.7158 11.1539 69.7158 10.6436C69.7158 10.1284 69.6473 9.67886 69.5117 9.29492C69.381 8.90617 69.1753 8.60445 68.8945 8.39062C68.6138 8.17213 68.2508 8.0625 67.8057 8.0625ZM53.3047 8.13574C52.8351 8.13574 52.4475 8.24222 52.1426 8.45605C51.8425 8.66504 51.6198 8.95977 51.4746 9.33887C51.3295 9.71303 51.2568 10.148 51.2568 10.6436C51.2568 11.4066 51.4288 12.0168 51.7725 12.4736C52.121 12.9256 52.6318 13.1514 53.3047 13.1514C54.0017 13.1514 54.5196 12.9177 54.8584 12.4512C55.1971 11.9846 55.3672 11.3822 55.3672 10.6436C55.3672 9.8807 55.1951 9.27324 54.8516 8.82129C54.5079 8.36444 53.9921 8.13575 53.3047 8.13574ZM76.8203 8.02637C76.1039 8.02637 75.5712 8.25013 75.2227 8.69727C74.9987 8.98144 74.8476 9.35094 74.7676 9.80566H78.6221C78.5589 9.29301 78.4236 8.89686 78.2139 8.61719C77.9186 8.22359 77.4543 8.02645 76.8203 8.02637Z",
918
+ fill: "black"
919
+ }
920
+ ),
921
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("defs", { children: [
922
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
923
+ "linearGradient",
924
+ {
925
+ id: "paint0_linear_2976_9475",
926
+ x1: "1.85883",
927
+ y1: "1.92425",
928
+ x2: "24.3072",
929
+ y2: "9.64016",
930
+ gradientUnits: "userSpaceOnUse",
931
+ children: [
932
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("stop", {}),
933
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("stop", { offset: "1", stopOpacity: "0.4" })
934
+ ]
935
+ }
936
+ ),
937
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
938
+ "linearGradient",
939
+ {
940
+ id: "paint1_linear_2976_9475",
941
+ x1: "25.6475",
942
+ y1: "8.65468",
943
+ x2: "10.7901",
944
+ y2: "8.65468",
945
+ gradientUnits: "userSpaceOnUse",
946
+ children: [
947
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("stop", {}),
948
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("stop", { offset: "1", stopOpacity: "0.4" })
949
+ ]
950
+ }
951
+ )
952
+ ] })
953
+ ]
954
+ }
955
+ )
956
+ }
957
+ )
958
+ ] })
959
+ ] }) }) });
960
+ }
961
+
962
+ // src/components/UserButton.tsx
963
+ var import_react5 = require("react");
964
+ var import_lucide_react5 = require("lucide-react");
965
+ var import_jsx_runtime7 = require("react/jsx-runtime");
966
+ function UserButton({
967
+ afterSignOutUrl = "/",
968
+ mode = "detailed",
969
+ appearance = {}
970
+ }) {
971
+ const { user, signOut } = useAuth();
972
+ const [isOpen, setIsOpen] = (0, import_react5.useState)(false);
973
+ const dropdownRef = (0, import_react5.useRef)(null);
974
+ (0, import_react5.useEffect)(() => {
975
+ function handleClickOutside(event) {
976
+ if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
977
+ setIsOpen(false);
978
+ }
979
+ }
980
+ if (isOpen) {
981
+ document.addEventListener("mousedown", handleClickOutside);
982
+ }
983
+ return () => {
984
+ document.removeEventListener("mousedown", handleClickOutside);
985
+ };
986
+ }, [isOpen]);
987
+ async function handleSignOut() {
988
+ await signOut();
989
+ setIsOpen(false);
990
+ window.location.href = afterSignOutUrl;
991
+ }
992
+ if (!user) return null;
993
+ const initials = user.nickname ? user.nickname.charAt(0).toUpperCase() : user.email.split("@")[0].slice(0, 2).toUpperCase();
994
+ const avatarUrl = user.avatar_url;
995
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "insforge-user-button-container", ref: dropdownRef, children: [
996
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
997
+ "button",
998
+ {
999
+ className: `insforge-user-button ${mode === "detailed" ? "insforge-user-button-detailed" : ""}`,
1000
+ onClick: () => setIsOpen(!isOpen),
1001
+ style: appearance.button,
1002
+ "aria-expanded": isOpen,
1003
+ "aria-haspopup": "true",
1004
+ children: [
1005
+ avatarUrl ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("img", { src: avatarUrl, alt: user.email, className: "insforge-user-avatar" }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "insforge-user-avatar-placeholder", children: initials }),
1006
+ mode === "detailed" && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "insforge-user-button-info", children: [
1007
+ user.nickname && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "insforge-user-button-name", children: user.nickname }),
1008
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "insforge-user-button-email", children: user.email })
1009
+ ] })
1010
+ ]
1011
+ }
1012
+ ),
1013
+ isOpen && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "insforge-user-dropdown", style: appearance.dropdown, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("button", { onClick: handleSignOut, className: "insforge-sign-out-button", children: [
1014
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_lucide_react5.LogOut, { className: "w-5 h-5" }),
1015
+ "Sign out"
1016
+ ] }) })
1017
+ ] });
1018
+ }
1019
+
1020
+ // src/components/SignedIn.tsx
1021
+ var import_jsx_runtime8 = require("react/jsx-runtime");
1022
+ function SignedIn({ children }) {
1023
+ const { isSignedIn, isLoaded } = useAuth();
1024
+ if (!isLoaded) return null;
1025
+ if (!isSignedIn) return null;
1026
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children });
1027
+ }
1028
+
1029
+ // src/components/SignedOut.tsx
1030
+ var import_jsx_runtime9 = require("react/jsx-runtime");
1031
+ function SignedOut({ children }) {
1032
+ const { isSignedIn, isLoaded } = useAuth();
1033
+ if (!isLoaded) return null;
1034
+ if (isSignedIn) return null;
1035
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_jsx_runtime9.Fragment, { children });
1036
+ }
1037
+
1038
+ // src/components/Protect.tsx
1039
+ var import_react6 = require("react");
1040
+ var import_navigation = require("next/navigation");
1041
+ var import_jsx_runtime10 = require("react/jsx-runtime");
1042
+ function Protect({
1043
+ children,
1044
+ fallback,
1045
+ redirectTo = "/sign-in",
1046
+ condition
1047
+ }) {
1048
+ const { isSignedIn, isLoaded, user } = useAuth();
1049
+ const router = (0, import_navigation.useRouter)();
1050
+ (0, import_react6.useEffect)(() => {
1051
+ if (isLoaded && !isSignedIn) {
1052
+ router.push(redirectTo);
1053
+ } else if (isLoaded && isSignedIn && condition && user) {
1054
+ if (!condition(user)) {
1055
+ router.push(redirectTo);
1056
+ }
1057
+ }
1058
+ }, [isLoaded, isSignedIn, redirectTo, router, condition, user]);
1059
+ if (!isLoaded) {
1060
+ return fallback || /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "insforge-loading", children: "Loading..." });
1061
+ }
1062
+ if (!isSignedIn) {
1063
+ return fallback || null;
1064
+ }
1065
+ if (condition && user && !condition(user)) {
1066
+ return fallback || null;
1067
+ }
1068
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_jsx_runtime10.Fragment, { children });
1069
+ }
1070
+ // Annotate the CommonJS export names for ESM import in node:
1071
+ 0 && (module.exports = {
1072
+ AuthProvider,
1073
+ InsforgeConfigProvider,
1074
+ Protect,
1075
+ SignIn,
1076
+ SignUp,
1077
+ SignedIn,
1078
+ SignedOut,
1079
+ UserButton,
1080
+ useAuth,
1081
+ useInsforgeConfig,
1082
+ useOAuthProviders,
1083
+ useSession,
1084
+ useUser
1085
+ });
1086
+ //# sourceMappingURL=index.js.map