@thetechfossil/auth2 1.2.1 → 1.2.3

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.mjs CHANGED
@@ -1,5 +1,6 @@
1
+ "use client";
1
2
  import axios from 'axios';
2
- import { useState, useCallback, useEffect } from 'react';
3
+ import { createContext, useState, useCallback, useEffect, useContext, useRef } from 'react';
3
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
4
5
 
5
6
  var __defProp = Object.defineProperty;
@@ -10,6 +11,7 @@ var __export = (target, all) => {
10
11
  var HttpClient = class {
11
12
  constructor(baseUrl, defaultHeaders = {}) {
12
13
  this.csrfToken = null;
14
+ this.frontendBaseUrl = null;
13
15
  this.axiosInstance = axios.create({
14
16
  baseURL: baseUrl.replace(/\/$/, ""),
15
17
  headers: {
@@ -26,6 +28,9 @@ var HttpClient = class {
26
28
  if (this.csrfToken && ["post", "put", "delete", "patch"].includes(config.method?.toLowerCase() || "")) {
27
29
  config.headers["x-csrf-token"] = this.csrfToken;
28
30
  }
31
+ if (this.frontendBaseUrl) {
32
+ config.headers["X-Frontend-URL"] = this.frontendBaseUrl;
33
+ }
29
34
  return config;
30
35
  },
31
36
  (error) => Promise.reject(error)
@@ -81,6 +86,15 @@ var HttpClient = class {
81
86
  removeCsrfToken() {
82
87
  this.csrfToken = null;
83
88
  }
89
+ setFrontendBaseUrl(url) {
90
+ this.frontendBaseUrl = url;
91
+ }
92
+ getFrontendBaseUrl() {
93
+ return this.frontendBaseUrl;
94
+ }
95
+ removeFrontendBaseUrl() {
96
+ this.frontendBaseUrl = null;
97
+ }
84
98
  async refreshCsrfToken() {
85
99
  try {
86
100
  const response = await this.axiosInstance.get("/api/v1/auth/csrf-token");
@@ -103,6 +117,12 @@ var AuthService = class {
103
117
  };
104
118
  this.httpClient = new HttpClient(this.config.baseUrl);
105
119
  this.loadTokenFromStorage();
120
+ if (typeof window !== "undefined") {
121
+ const frontendBaseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || process.env.NEXT_PUBLIC_APP_URL || window.location.origin;
122
+ if (frontendBaseUrl) {
123
+ this.httpClient.setFrontendBaseUrl(frontendBaseUrl);
124
+ }
125
+ }
106
126
  if (this.config.csrfEnabled && typeof window !== "undefined") {
107
127
  this.refreshCsrfToken();
108
128
  }
@@ -219,11 +239,7 @@ var AuthService = class {
219
239
  throw new Error(response.message || "Login failed");
220
240
  }
221
241
  async register(data) {
222
- const registerData = { ...data };
223
- if (!registerData.frontendBaseUrl && typeof window !== "undefined") {
224
- registerData.frontendBaseUrl = process.env.FRONTEND_BASE_URL || process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || process.env.NEXT_PUBLIC_APP_URL || window.location.origin;
225
- }
226
- const response = await this.httpClient.post("/api/v1/auth/register", registerData);
242
+ const response = await this.httpClient.post("/api/v1/auth/register", data);
227
243
  if (response.success && response.message === "Registration data saved. Verification email sent. Please check your inbox.") {
228
244
  return response;
229
245
  }
@@ -239,15 +255,33 @@ var AuthService = class {
239
255
  return response;
240
256
  }
241
257
  async verifyEmailToken(token) {
242
- const response = await this.httpClient.get(`/api/v1/auth/verify-email?token=${token}`);
243
- if (response.success && response.token) {
244
- this.token = response.token;
245
- this.httpClient.setAuthToken(response.token);
246
- this.saveTokenToStorage(response.token);
258
+ try {
259
+ const response = await this.httpClient.get(`/api/v1/auth/verify-email?token=${token}`);
260
+ if (response.success && response.token) {
261
+ this.token = response.token;
262
+ this.httpClient.setAuthToken(response.token);
263
+ this.saveTokenToStorage(response.token);
264
+ }
265
+ return response;
266
+ } catch (error) {
267
+ if (error.response?.data) {
268
+ return {
269
+ success: false,
270
+ message: error.response.data.message || "Email verification failed"
271
+ };
272
+ }
273
+ return {
274
+ success: false,
275
+ message: error.message || "Network error occurred"
276
+ };
247
277
  }
248
- return response;
249
278
  }
250
279
  async logout() {
280
+ try {
281
+ await this.httpClient.post("/api/v1/auth/logout", {});
282
+ } catch (error) {
283
+ console.warn("Failed to call logout endpoint:", error);
284
+ }
251
285
  this.token = null;
252
286
  this.httpClient.removeAuthToken();
253
287
  this.httpClient.removeCsrfToken();
@@ -284,9 +318,6 @@ var AuthService = class {
284
318
  return response.user;
285
319
  }
286
320
  async forgotPassword(email) {
287
- if (typeof window !== "undefined") {
288
- process.env.FRONTEND_BASE_URL || process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || process.env.NEXT_PUBLIC_APP_URL || window.location.origin;
289
- }
290
321
  const response = await this.httpClient.post("/api/v1/auth/forgot-password", { email });
291
322
  return response;
292
323
  }
@@ -294,70 +325,208 @@ var AuthService = class {
294
325
  const response = await this.httpClient.post("/api/v1/auth/reset-password", { token, password });
295
326
  return response;
296
327
  }
328
+ async changePassword(oldPassword, newPassword) {
329
+ if (!this.token) {
330
+ throw new Error("Not authenticated");
331
+ }
332
+ const response = await this.httpClient.post("/api/v1/user/change-password", {
333
+ oldPassword,
334
+ newPassword
335
+ });
336
+ return response;
337
+ }
338
+ async updateAvatar(avatar) {
339
+ if (!this.token) {
340
+ throw new Error("Not authenticated");
341
+ }
342
+ const response = await this.httpClient.post("/api/v1/user/update/avatar", { avatar });
343
+ if (response.success && response.token) {
344
+ this.token = response.token;
345
+ this.httpClient.setAuthToken(response.token);
346
+ this.saveTokenToStorage(response.token);
347
+ }
348
+ return response;
349
+ }
350
+ async requestEmailChange(newEmail) {
351
+ if (!this.token) {
352
+ throw new Error("Not authenticated");
353
+ }
354
+ const response = await this.httpClient.post("/api/v1/user/request-email-change", {
355
+ newEmail
356
+ });
357
+ return response;
358
+ }
359
+ async verifyEmailChange(token) {
360
+ const response = await this.httpClient.get(`/api/v1/user/verify-email-change?token=${token}`);
361
+ if (response.success && response.token) {
362
+ this.token = response.token;
363
+ this.httpClient.setAuthToken(response.token);
364
+ this.saveTokenToStorage(response.token);
365
+ }
366
+ return response;
367
+ }
368
+ // 2FA / MFA Methods
369
+ async generate2FA() {
370
+ if (!this.token) {
371
+ throw new Error("Not authenticated");
372
+ }
373
+ const response = await this.httpClient.post(
374
+ "/api/v1/mfa/generate",
375
+ {}
376
+ );
377
+ return response;
378
+ }
379
+ async enable2FA(token) {
380
+ if (!this.token) {
381
+ throw new Error("Not authenticated");
382
+ }
383
+ const response = await this.httpClient.post("/api/v1/mfa/enable", { token });
384
+ return response;
385
+ }
386
+ async disable2FA(token) {
387
+ if (!this.token) {
388
+ throw new Error("Not authenticated");
389
+ }
390
+ const response = await this.httpClient.post("/api/v1/mfa/disable", { token });
391
+ return response;
392
+ }
393
+ async validate2FA(token) {
394
+ if (!this.token) {
395
+ throw new Error("Not authenticated");
396
+ }
397
+ const response = await this.httpClient.post("/api/v1/mfa/validate", { token });
398
+ return response;
399
+ }
400
+ // Session Management Methods
401
+ async getSessions() {
402
+ if (!this.token) {
403
+ throw new Error("Not authenticated");
404
+ }
405
+ const response = await this.httpClient.get("/api/v1/sessions");
406
+ return response;
407
+ }
408
+ async revokeSession(sessionId) {
409
+ if (!this.token) {
410
+ throw new Error("Not authenticated");
411
+ }
412
+ const response = await this.httpClient.delete(`/api/v1/sessions/${sessionId}`);
413
+ return response;
414
+ }
415
+ async revokeAllSessions() {
416
+ if (!this.token) {
417
+ throw new Error("Not authenticated");
418
+ }
419
+ const response = await this.httpClient.delete("/api/v1/sessions/revoke/all");
420
+ this.token = null;
421
+ this.httpClient.removeAuthToken();
422
+ this.removeTokenFromStorage();
423
+ return response;
424
+ }
425
+ // Admin Methods
426
+ async getAuditLogs(filters) {
427
+ if (!this.token) {
428
+ throw new Error("Not authenticated");
429
+ }
430
+ const response = await this.httpClient.get(
431
+ "/api/v1/admin/audit-logs",
432
+ filters
433
+ );
434
+ return response;
435
+ }
436
+ async adminVerifyUser(userId) {
437
+ if (!this.token) {
438
+ throw new Error("Not authenticated");
439
+ }
440
+ const response = await this.httpClient.post(`/api/v1/admin/verify-user/${userId}`, {});
441
+ return response;
442
+ }
443
+ async adminForcePasswordReset(userId) {
444
+ if (!this.token) {
445
+ throw new Error("Not authenticated");
446
+ }
447
+ const response = await this.httpClient.post(`/api/v1/admin/force-password-reset/${userId}`, {});
448
+ return response;
449
+ }
450
+ async adminSuspendUser(userId) {
451
+ if (!this.token) {
452
+ throw new Error("Not authenticated");
453
+ }
454
+ const response = await this.httpClient.post(`/api/v1/admin/suspend-user/${userId}`, {});
455
+ return response;
456
+ }
457
+ async adminActivateUser(userId) {
458
+ if (!this.token) {
459
+ throw new Error("Not authenticated");
460
+ }
461
+ const response = await this.httpClient.post(`/api/v1/admin/activate-user/${userId}`, {});
462
+ return response;
463
+ }
297
464
  };
298
-
299
- // src/react/index.ts
300
- var react_exports = {};
301
- __export(react_exports, {
302
- AuthFlow: () => AuthFlow,
303
- EmailVerificationPage: () => EmailVerificationPage,
304
- LoginForm: () => LoginForm,
305
- OtpForm: () => OtpForm,
306
- RegisterForm: () => RegisterForm,
307
- useAuth: () => useAuth
308
- });
309
- var useAuth = (config) => {
310
- const [authService] = useState(() => new AuthService(config));
465
+ var AuthContext = createContext(void 0);
466
+ var AuthProvider = ({ children, config }) => {
467
+ const authConfig = {
468
+ baseUrl: config?.baseUrl || (typeof window !== "undefined" ? process.env.NEXT_PUBLIC_AUTH_API_URL || process.env.REACT_APP_AUTH_API_URL || "http://localhost:7000" : "http://localhost:7000"),
469
+ localStorageKey: config?.localStorageKey || "auth_token",
470
+ csrfEnabled: config?.csrfEnabled !== void 0 ? config.csrfEnabled : true
471
+ };
472
+ const [authService] = useState(() => new AuthService(authConfig));
311
473
  const [user, setUser] = useState(null);
312
- const [isAuthenticated, setIsAuthenticated] = useState(false);
313
- const [loading, setLoading] = useState(true);
314
- const checkAuthStatus = useCallback(() => {
474
+ const [isLoaded, setIsLoaded] = useState(false);
475
+ const [loading, setLoading] = useState(false);
476
+ const checkAuthStatus = useCallback(async () => {
315
477
  const authenticated = authService.isAuthenticated();
316
- setIsAuthenticated(authenticated);
317
478
  if (authenticated) {
318
- const currentUser = authService.getCurrentUser();
319
- setUser(currentUser);
479
+ try {
480
+ const currentUser = authService.getCurrentUser();
481
+ setUser(currentUser);
482
+ } catch (error) {
483
+ console.error("Failed to get current user:", error);
484
+ setUser(null);
485
+ }
320
486
  } else {
321
487
  setUser(null);
322
488
  }
323
- setLoading(false);
489
+ setIsLoaded(true);
324
490
  }, [authService]);
325
491
  useEffect(() => {
326
492
  checkAuthStatus();
327
493
  }, [checkAuthStatus]);
328
- const register = useCallback(async (data) => {
494
+ const signIn = useCallback(async (data) => {
329
495
  setLoading(true);
330
496
  try {
331
- const registerData = { ...data };
332
- if (!registerData.frontendBaseUrl && typeof window !== "undefined") {
333
- registerData.frontendBaseUrl = process.env.REACT_APP_FRONTEND_BASE_URL || process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.NEXT_PUBLIC_APP_URL || window.location.origin;
497
+ const response = await authService.login(data);
498
+ if (response.success && response.user) {
499
+ setUser(response.user);
334
500
  }
335
- const response = await authService.register(registerData);
336
501
  return response;
337
502
  } finally {
338
503
  setLoading(false);
339
504
  }
340
505
  }, [authService]);
341
- const login = useCallback(async (data) => {
506
+ const signUp = useCallback(async (data) => {
342
507
  setLoading(true);
343
508
  try {
344
- const response = await authService.login(data);
345
- if (response.success && response.user) {
346
- setUser(response.user);
347
- setIsAuthenticated(true);
348
- }
509
+ const response = await authService.register(data);
349
510
  return response;
350
511
  } finally {
351
512
  setLoading(false);
352
513
  }
353
514
  }, [authService]);
515
+ const signOut = useCallback(async () => {
516
+ setLoading(true);
517
+ try {
518
+ await authService.logout();
519
+ setUser(null);
520
+ } finally {
521
+ setLoading(false);
522
+ }
523
+ }, [authService]);
354
524
  const verify = useCallback(async (data) => {
355
525
  setLoading(true);
356
526
  try {
357
527
  const response = await authService.verify(data);
358
528
  if (response.success && response.user) {
359
529
  setUser(response.user);
360
- setIsAuthenticated(true);
361
530
  }
362
531
  return response;
363
532
  } finally {
@@ -370,23 +539,12 @@ var useAuth = (config) => {
370
539
  const response = await authService.verifyEmailToken(token);
371
540
  if (response.success && response.user) {
372
541
  setUser(response.user);
373
- setIsAuthenticated(true);
374
542
  }
375
543
  return response;
376
544
  } finally {
377
545
  setLoading(false);
378
546
  }
379
547
  }, [authService]);
380
- const logout = useCallback(async () => {
381
- setLoading(true);
382
- try {
383
- await authService.logout();
384
- setUser(null);
385
- setIsAuthenticated(false);
386
- } finally {
387
- setLoading(false);
388
- }
389
- }, [authService]);
390
548
  const updateProfile = useCallback(async (data) => {
391
549
  setLoading(true);
392
550
  try {
@@ -409,90 +567,356 @@ var useAuth = (config) => {
409
567
  setLoading(false);
410
568
  }
411
569
  }, [authService]);
412
- const getAllUsers = useCallback(async () => {
570
+ const signInWithOAuth = useCallback((provider) => {
571
+ authService.loginWithOAuth(provider);
572
+ }, [authService]);
573
+ const linkOAuthProvider = useCallback((provider) => {
574
+ authService.linkOAuthProvider(provider);
575
+ }, [authService]);
576
+ const unlinkOAuthProvider = useCallback(async (provider) => {
413
577
  setLoading(true);
414
578
  try {
415
- return await authService.getAllUsers();
579
+ return await authService.unlinkOAuthProvider(provider);
416
580
  } finally {
417
581
  setLoading(false);
418
582
  }
419
583
  }, [authService]);
420
- const getUserById = useCallback(async (id) => {
584
+ const forgotPassword = useCallback(async (email) => {
421
585
  setLoading(true);
422
586
  try {
423
- return await authService.getUserById(id);
587
+ return await authService.forgotPassword(email);
424
588
  } finally {
425
589
  setLoading(false);
426
590
  }
427
591
  }, [authService]);
428
- return {
429
- user,
430
- isAuthenticated,
431
- loading,
432
- register,
433
- login,
434
- verify,
435
- verifyEmailToken,
436
- logout,
437
- updateProfile,
438
- getProfile,
439
- getAllUsers,
440
- getUserById
441
- };
442
- };
443
- var LoginForm = ({
444
- onSuccess,
445
- onLoginSuccess,
446
- onRegisterClick,
447
- showRegisterLink = true,
448
- config,
449
- oauthProviders = ["google", "github"],
450
- showOAuthButtons = true
451
- }) => {
452
- const [email, setEmail] = useState("");
453
- const [password, setPassword] = useState("");
454
- const [usePassword, setUsePassword] = useState(false);
455
- const [showPassword, setShowPassword] = useState(false);
456
- const [isLoading, setIsLoading] = useState(false);
457
- const [error, setError] = useState(null);
458
- const [rememberMe, setRememberMe] = useState(false);
459
- const { login } = useAuth({
460
- baseUrl: config?.baseUrl || (typeof window !== "undefined" ? window.location.origin : "http://localhost:7000")
461
- });
462
- const handleSubmit = async (e) => {
463
- e.preventDefault();
464
- setIsLoading(true);
465
- setError(null);
592
+ const resetPassword = useCallback(async (token, password) => {
593
+ setLoading(true);
466
594
  try {
467
- let response;
468
- if (usePassword) {
469
- response = await login({ email, password });
470
- } else {
471
- response = await login({ email });
472
- }
473
- if (response.success) {
474
- onSuccess?.(response);
475
- if (onLoginSuccess) {
476
- if (response.message === "OTP sent to your email.") {
477
- onLoginSuccess(email, true);
478
- } else if (response.token) {
479
- onLoginSuccess(email, false);
480
- } else {
481
- onLoginSuccess(email, true);
482
- }
483
- }
484
- } else {
485
- setError(response.message || "Login failed");
595
+ return await authService.resetPassword(token, password);
596
+ } finally {
597
+ setLoading(false);
598
+ }
599
+ }, [authService]);
600
+ const changePassword = useCallback(async (oldPassword, newPassword) => {
601
+ setLoading(true);
602
+ try {
603
+ return await authService.changePassword(oldPassword, newPassword);
604
+ } finally {
605
+ setLoading(false);
606
+ }
607
+ }, [authService]);
608
+ const updateAvatar = useCallback(async (avatar) => {
609
+ setLoading(true);
610
+ try {
611
+ const response = await authService.updateAvatar(avatar);
612
+ if (response.success && response.user) {
613
+ setUser(response.user);
486
614
  }
487
- } catch (err) {
488
- setError(err instanceof Error ? err.message : "An unknown error occurred");
615
+ return response;
489
616
  } finally {
490
- setIsLoading(false);
617
+ setLoading(false);
491
618
  }
492
- };
493
- const toggleAuthMethod = () => {
494
- setUsePassword(!usePassword);
495
- setError(null);
619
+ }, [authService]);
620
+ const requestEmailChange = useCallback(async (newEmail) => {
621
+ setLoading(true);
622
+ try {
623
+ return await authService.requestEmailChange(newEmail);
624
+ } finally {
625
+ setLoading(false);
626
+ }
627
+ }, [authService]);
628
+ const verifyEmailChange = useCallback(async (token) => {
629
+ setLoading(true);
630
+ try {
631
+ const response = await authService.verifyEmailChange(token);
632
+ if (response.success && response.user) {
633
+ setUser(response.user);
634
+ }
635
+ return response;
636
+ } finally {
637
+ setLoading(false);
638
+ }
639
+ }, [authService]);
640
+ const generate2FA = useCallback(async () => {
641
+ setLoading(true);
642
+ try {
643
+ return await authService.generate2FA();
644
+ } finally {
645
+ setLoading(false);
646
+ }
647
+ }, [authService]);
648
+ const enable2FA = useCallback(async (token) => {
649
+ setLoading(true);
650
+ try {
651
+ return await authService.enable2FA(token);
652
+ } finally {
653
+ setLoading(false);
654
+ }
655
+ }, [authService]);
656
+ const disable2FA = useCallback(async (token) => {
657
+ setLoading(true);
658
+ try {
659
+ return await authService.disable2FA(token);
660
+ } finally {
661
+ setLoading(false);
662
+ }
663
+ }, [authService]);
664
+ const validate2FA = useCallback(async (token) => {
665
+ setLoading(true);
666
+ try {
667
+ return await authService.validate2FA(token);
668
+ } finally {
669
+ setLoading(false);
670
+ }
671
+ }, [authService]);
672
+ const getSessions = useCallback(async () => {
673
+ setLoading(true);
674
+ try {
675
+ return await authService.getSessions();
676
+ } finally {
677
+ setLoading(false);
678
+ }
679
+ }, [authService]);
680
+ const revokeSession = useCallback(async (sessionId) => {
681
+ setLoading(true);
682
+ try {
683
+ return await authService.revokeSession(sessionId);
684
+ } finally {
685
+ setLoading(false);
686
+ }
687
+ }, [authService]);
688
+ const revokeAllSessions = useCallback(async () => {
689
+ setLoading(true);
690
+ try {
691
+ const response = await authService.revokeAllSessions();
692
+ setUser(null);
693
+ return response;
694
+ } finally {
695
+ setLoading(false);
696
+ }
697
+ }, [authService]);
698
+ const value = {
699
+ user,
700
+ isLoaded,
701
+ isSignedIn: !!user,
702
+ loading,
703
+ signIn,
704
+ signUp,
705
+ signOut,
706
+ verify,
707
+ verifyEmailToken,
708
+ updateProfile,
709
+ getProfile,
710
+ signInWithOAuth,
711
+ linkOAuthProvider,
712
+ unlinkOAuthProvider,
713
+ forgotPassword,
714
+ resetPassword,
715
+ changePassword,
716
+ updateAvatar,
717
+ requestEmailChange,
718
+ verifyEmailChange,
719
+ generate2FA,
720
+ enable2FA,
721
+ disable2FA,
722
+ validate2FA,
723
+ getSessions,
724
+ revokeSession,
725
+ revokeAllSessions,
726
+ authService
727
+ };
728
+ return /* @__PURE__ */ jsx(AuthContext.Provider, { value, children });
729
+ };
730
+ var useAuth = () => {
731
+ const context = useContext(AuthContext);
732
+ if (context === void 0) {
733
+ throw new Error("useAuth must be used within an AuthProvider");
734
+ }
735
+ return context;
736
+ };
737
+ var useAuth2 = (config) => {
738
+ const [authService] = useState(() => new AuthService(config));
739
+ const [user, setUser] = useState(null);
740
+ const [isAuthenticated, setIsAuthenticated] = useState(false);
741
+ const [loading, setLoading] = useState(true);
742
+ const checkAuthStatus = useCallback(() => {
743
+ const authenticated = authService.isAuthenticated();
744
+ setIsAuthenticated(authenticated);
745
+ if (authenticated) {
746
+ const currentUser = authService.getCurrentUser();
747
+ setUser(currentUser);
748
+ } else {
749
+ setUser(null);
750
+ }
751
+ setLoading(false);
752
+ }, [authService]);
753
+ useEffect(() => {
754
+ checkAuthStatus();
755
+ }, [checkAuthStatus]);
756
+ const register = useCallback(async (data) => {
757
+ setLoading(true);
758
+ try {
759
+ const response = await authService.register(data);
760
+ return response;
761
+ } finally {
762
+ setLoading(false);
763
+ }
764
+ }, [authService]);
765
+ const login = useCallback(async (data) => {
766
+ setLoading(true);
767
+ try {
768
+ const response = await authService.login(data);
769
+ if (response.success && response.user) {
770
+ setUser(response.user);
771
+ setIsAuthenticated(true);
772
+ }
773
+ return response;
774
+ } finally {
775
+ setLoading(false);
776
+ }
777
+ }, [authService]);
778
+ const verify = useCallback(async (data) => {
779
+ setLoading(true);
780
+ try {
781
+ const response = await authService.verify(data);
782
+ if (response.success && response.user) {
783
+ setUser(response.user);
784
+ setIsAuthenticated(true);
785
+ }
786
+ return response;
787
+ } finally {
788
+ setLoading(false);
789
+ }
790
+ }, [authService]);
791
+ const verifyEmailToken = useCallback(async (token) => {
792
+ setLoading(true);
793
+ try {
794
+ const response = await authService.verifyEmailToken(token);
795
+ if (response.success && response.user) {
796
+ setUser(response.user);
797
+ setIsAuthenticated(true);
798
+ }
799
+ return response;
800
+ } finally {
801
+ setLoading(false);
802
+ }
803
+ }, [authService]);
804
+ const logout = useCallback(async () => {
805
+ setLoading(true);
806
+ try {
807
+ await authService.logout();
808
+ setUser(null);
809
+ setIsAuthenticated(false);
810
+ } finally {
811
+ setLoading(false);
812
+ }
813
+ }, [authService]);
814
+ const updateProfile = useCallback(async (data) => {
815
+ setLoading(true);
816
+ try {
817
+ const response = await authService.updateProfile(data);
818
+ if (response.success && response.user) {
819
+ setUser(response.user);
820
+ }
821
+ return response;
822
+ } finally {
823
+ setLoading(false);
824
+ }
825
+ }, [authService]);
826
+ const getProfile = useCallback(async () => {
827
+ setLoading(true);
828
+ try {
829
+ const userData = await authService.getProfile();
830
+ setUser(userData);
831
+ return userData;
832
+ } finally {
833
+ setLoading(false);
834
+ }
835
+ }, [authService]);
836
+ const getAllUsers = useCallback(async () => {
837
+ setLoading(true);
838
+ try {
839
+ return await authService.getAllUsers();
840
+ } finally {
841
+ setLoading(false);
842
+ }
843
+ }, [authService]);
844
+ const getUserById = useCallback(async (id) => {
845
+ setLoading(true);
846
+ try {
847
+ return await authService.getUserById(id);
848
+ } finally {
849
+ setLoading(false);
850
+ }
851
+ }, [authService]);
852
+ return {
853
+ user,
854
+ isAuthenticated,
855
+ loading,
856
+ register,
857
+ login,
858
+ verify,
859
+ verifyEmailToken,
860
+ logout,
861
+ updateProfile,
862
+ getProfile,
863
+ getAllUsers,
864
+ getUserById
865
+ };
866
+ };
867
+ var LoginForm = ({
868
+ onSuccess,
869
+ onLoginSuccess,
870
+ onRegisterClick,
871
+ showRegisterLink = true,
872
+ config,
873
+ oauthProviders = ["google", "github"],
874
+ showOAuthButtons = true
875
+ }) => {
876
+ const [email, setEmail] = useState("");
877
+ const [password, setPassword] = useState("");
878
+ const [usePassword, setUsePassword] = useState(false);
879
+ const [showPassword, setShowPassword] = useState(false);
880
+ const [isLoading, setIsLoading] = useState(false);
881
+ const [error, setError] = useState(null);
882
+ const [rememberMe, setRememberMe] = useState(false);
883
+ const { login } = useAuth2({
884
+ baseUrl: config?.baseUrl || (typeof window !== "undefined" ? window.location.origin : "http://localhost:7000")
885
+ });
886
+ const handleSubmit = async (e) => {
887
+ e.preventDefault();
888
+ setIsLoading(true);
889
+ setError(null);
890
+ try {
891
+ let response;
892
+ if (usePassword) {
893
+ response = await login({ email, password });
894
+ } else {
895
+ response = await login({ email });
896
+ }
897
+ if (response.success) {
898
+ onSuccess?.(response);
899
+ if (onLoginSuccess) {
900
+ if (response.message === "OTP sent to your email.") {
901
+ onLoginSuccess(email, true);
902
+ } else if (response.token) {
903
+ onLoginSuccess(email, false);
904
+ } else {
905
+ onLoginSuccess(email, true);
906
+ }
907
+ }
908
+ } else {
909
+ setError(response.message || "Login failed");
910
+ }
911
+ } catch (err) {
912
+ setError(err instanceof Error ? err.message : "An unknown error occurred");
913
+ } finally {
914
+ setIsLoading(false);
915
+ }
916
+ };
917
+ const toggleAuthMethod = () => {
918
+ setUsePassword(!usePassword);
919
+ setError(null);
496
920
  };
497
921
  const togglePasswordVisibility = () => {
498
922
  setShowPassword(!showPassword);
@@ -900,7 +1324,7 @@ var RegisterForm = ({
900
1324
  const config = authConfig || {
901
1325
  baseUrl: typeof window !== "undefined" ? process.env.NEXT_PUBLIC_AUTH_API_URL || window.location.origin : "http://localhost:7000"
902
1326
  };
903
- const { register } = useAuth(config);
1327
+ const { register } = useAuth2(config);
904
1328
  const handleSubmit = async (e) => {
905
1329
  e.preventDefault();
906
1330
  setIsLoading(true);
@@ -1295,7 +1719,7 @@ var OtpForm = ({
1295
1719
  const [error, setError] = useState(null);
1296
1720
  const [resendCooldown, setResendCooldown] = useState(0);
1297
1721
  const [resendLoading, setResendLoading] = useState(false);
1298
- const { verify, login } = useAuth({
1722
+ const { verify, login } = useAuth2({
1299
1723
  baseUrl: typeof window !== "undefined" ? window.location.origin : "http://localhost:7000"
1300
1724
  });
1301
1725
  const handleSubmit = async (e) => {
@@ -1646,7 +2070,7 @@ var EmailVerificationPage = ({
1646
2070
  const [isLoading, setIsLoading] = useState(true);
1647
2071
  const [message, setMessage] = useState("");
1648
2072
  const [isSuccess, setIsSuccess] = useState(false);
1649
- const { verifyEmailToken } = useAuth({
2073
+ const { verifyEmailToken } = useAuth2({
1650
2074
  baseUrl: baseUrl || (typeof window !== "undefined" ? window.location.origin : "http://localhost:7000")
1651
2075
  });
1652
2076
  useEffect(() => {
@@ -1754,6 +2178,1825 @@ var EmailVerificationPage = ({
1754
2178
  ] })
1755
2179
  ] }) });
1756
2180
  };
2181
+ var SignIn = ({ redirectUrl, appearance }) => {
2182
+ const { signIn, isSignedIn, loading: authLoading } = useAuth();
2183
+ const [email, setEmail] = useState("");
2184
+ const [password, setPassword] = useState("");
2185
+ const [otp, setOtp] = useState("");
2186
+ const [usePassword, setUsePassword] = useState(false);
2187
+ const [showPassword, setShowPassword] = useState(false);
2188
+ const [isLoading, setIsLoading] = useState(false);
2189
+ const [error, setError] = useState(null);
2190
+ const [needsOtp, setNeedsOtp] = useState(false);
2191
+ const [success, setSuccess] = useState(null);
2192
+ useEffect(() => {
2193
+ if (isSignedIn && redirectUrl) {
2194
+ const redirect = redirectUrl || process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_AFTER_LOGIN || "/dashboard";
2195
+ const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
2196
+ window.location.href = `${baseUrl}${redirect}`;
2197
+ }
2198
+ }, [isSignedIn, redirectUrl]);
2199
+ const handleSubmit = async (e) => {
2200
+ e.preventDefault();
2201
+ setIsLoading(true);
2202
+ setError(null);
2203
+ setSuccess(null);
2204
+ try {
2205
+ if (needsOtp) {
2206
+ const response = await signIn({ email, otp });
2207
+ if (response.success) {
2208
+ setSuccess("Login successful!");
2209
+ } else {
2210
+ setError(response.message || "OTP verification failed");
2211
+ }
2212
+ } else if (usePassword) {
2213
+ const response = await signIn({ email, password });
2214
+ if (response.success) {
2215
+ setSuccess("Login successful!");
2216
+ } else {
2217
+ setError(response.message || "Login failed");
2218
+ }
2219
+ } else {
2220
+ const response = await signIn({ email });
2221
+ if (response.success && response.message === "OTP sent to your email.") {
2222
+ setNeedsOtp(true);
2223
+ setSuccess("OTP sent to your email. Please check your inbox.");
2224
+ } else {
2225
+ setError(response.message || "Failed to send OTP");
2226
+ }
2227
+ }
2228
+ } catch (err) {
2229
+ setError(err instanceof Error ? err.message : "An error occurred");
2230
+ } finally {
2231
+ setIsLoading(false);
2232
+ }
2233
+ };
2234
+ const toggleAuthMethod = () => {
2235
+ setUsePassword(!usePassword);
2236
+ setNeedsOtp(false);
2237
+ setError(null);
2238
+ setSuccess(null);
2239
+ setOtp("");
2240
+ };
2241
+ if (authLoading) {
2242
+ return /* @__PURE__ */ jsx("div", { style: { textAlign: "center", padding: "40px" }, children: /* @__PURE__ */ jsx("div", { children: "Loading..." }) });
2243
+ }
2244
+ return /* @__PURE__ */ jsx("div", { style: {
2245
+ maxWidth: "400px",
2246
+ margin: "0 auto",
2247
+ padding: "30px",
2248
+ borderRadius: "12px",
2249
+ boxShadow: "0 4px 20px rgba(0, 0, 0, 0.1)",
2250
+ backgroundColor: "#ffffff",
2251
+ border: "1px solid #eaeaea",
2252
+ ...appearance?.elements?.card
2253
+ }, children: /* @__PURE__ */ jsxs("form", { onSubmit: handleSubmit, children: [
2254
+ /* @__PURE__ */ jsx("h2", { style: {
2255
+ textAlign: "center",
2256
+ marginBottom: "24px",
2257
+ color: "#1f2937",
2258
+ fontSize: "24px",
2259
+ fontWeight: 600,
2260
+ ...appearance?.elements?.headerTitle
2261
+ }, children: needsOtp ? "Enter OTP" : usePassword ? "Sign in with password" : "Sign in" }),
2262
+ error && /* @__PURE__ */ jsx("div", { style: {
2263
+ padding: "12px 16px",
2264
+ marginBottom: "20px",
2265
+ backgroundColor: "#fee",
2266
+ color: "#c33",
2267
+ border: "1px solid #fcc",
2268
+ borderRadius: "8px",
2269
+ fontSize: "14px"
2270
+ }, children: error }),
2271
+ success && /* @__PURE__ */ jsx("div", { style: {
2272
+ padding: "12px 16px",
2273
+ marginBottom: "20px",
2274
+ backgroundColor: "#efe",
2275
+ color: "#3c3",
2276
+ border: "1px solid #cfc",
2277
+ borderRadius: "8px",
2278
+ fontSize: "14px"
2279
+ }, children: success }),
2280
+ !needsOtp && /* @__PURE__ */ jsxs("div", { style: { marginBottom: "20px" }, children: [
2281
+ /* @__PURE__ */ jsx("label", { htmlFor: "email", style: {
2282
+ display: "block",
2283
+ marginBottom: "8px",
2284
+ fontWeight: 500,
2285
+ color: "#374151",
2286
+ fontSize: "14px"
2287
+ }, children: "Email" }),
2288
+ /* @__PURE__ */ jsx(
2289
+ "input",
2290
+ {
2291
+ id: "email",
2292
+ type: "email",
2293
+ value: email,
2294
+ onChange: (e) => setEmail(e.target.value),
2295
+ required: true,
2296
+ disabled: isLoading,
2297
+ style: {
2298
+ width: "100%",
2299
+ padding: "12px 16px",
2300
+ border: "1px solid #ddd",
2301
+ borderRadius: "8px",
2302
+ fontSize: "16px",
2303
+ boxSizing: "border-box",
2304
+ ...appearance?.elements?.formFieldInput
2305
+ },
2306
+ placeholder: "Enter your email"
2307
+ }
2308
+ )
2309
+ ] }),
2310
+ usePassword && !needsOtp && /* @__PURE__ */ jsxs("div", { style: { marginBottom: "20px", position: "relative" }, children: [
2311
+ /* @__PURE__ */ jsx("label", { htmlFor: "password", style: {
2312
+ display: "block",
2313
+ marginBottom: "8px",
2314
+ fontWeight: 500,
2315
+ color: "#374151",
2316
+ fontSize: "14px"
2317
+ }, children: "Password" }),
2318
+ /* @__PURE__ */ jsx(
2319
+ "input",
2320
+ {
2321
+ id: "password",
2322
+ type: showPassword ? "text" : "password",
2323
+ value: password,
2324
+ onChange: (e) => setPassword(e.target.value),
2325
+ required: true,
2326
+ disabled: isLoading,
2327
+ style: {
2328
+ width: "100%",
2329
+ padding: "12px 16px",
2330
+ border: "1px solid #ddd",
2331
+ borderRadius: "8px",
2332
+ fontSize: "16px",
2333
+ boxSizing: "border-box",
2334
+ ...appearance?.elements?.formFieldInput
2335
+ },
2336
+ placeholder: "Enter your password"
2337
+ }
2338
+ ),
2339
+ /* @__PURE__ */ jsx(
2340
+ "button",
2341
+ {
2342
+ type: "button",
2343
+ onClick: () => setShowPassword(!showPassword),
2344
+ style: {
2345
+ position: "absolute",
2346
+ right: "12px",
2347
+ top: "38px",
2348
+ background: "none",
2349
+ border: "none",
2350
+ cursor: "pointer",
2351
+ color: "#666",
2352
+ fontSize: "14px"
2353
+ },
2354
+ children: showPassword ? "Hide" : "Show"
2355
+ }
2356
+ )
2357
+ ] }),
2358
+ needsOtp && /* @__PURE__ */ jsxs("div", { style: { marginBottom: "20px" }, children: [
2359
+ /* @__PURE__ */ jsx("label", { htmlFor: "otp", style: {
2360
+ display: "block",
2361
+ marginBottom: "8px",
2362
+ fontWeight: 500,
2363
+ color: "#374151",
2364
+ fontSize: "14px"
2365
+ }, children: "One-Time Password" }),
2366
+ /* @__PURE__ */ jsx(
2367
+ "input",
2368
+ {
2369
+ id: "otp",
2370
+ type: "text",
2371
+ value: otp,
2372
+ onChange: (e) => setOtp(e.target.value),
2373
+ required: true,
2374
+ disabled: isLoading,
2375
+ maxLength: 6,
2376
+ style: {
2377
+ width: "100%",
2378
+ padding: "12px 16px",
2379
+ border: "1px solid #ddd",
2380
+ borderRadius: "8px",
2381
+ fontSize: "16px",
2382
+ boxSizing: "border-box",
2383
+ letterSpacing: "0.5em",
2384
+ textAlign: "center",
2385
+ ...appearance?.elements?.formFieldInput
2386
+ },
2387
+ placeholder: "000000"
2388
+ }
2389
+ )
2390
+ ] }),
2391
+ /* @__PURE__ */ jsx(
2392
+ "button",
2393
+ {
2394
+ type: "submit",
2395
+ disabled: isLoading,
2396
+ style: {
2397
+ width: "100%",
2398
+ padding: "14px",
2399
+ backgroundColor: "#007bff",
2400
+ color: "white",
2401
+ border: "none",
2402
+ borderRadius: "8px",
2403
+ fontSize: "16px",
2404
+ fontWeight: 600,
2405
+ cursor: "pointer",
2406
+ transition: "all 0.2s ease",
2407
+ ...appearance?.elements?.formButtonPrimary
2408
+ },
2409
+ children: isLoading ? "Please wait..." : needsOtp ? "Verify OTP" : usePassword ? "Sign in" : "Continue with email"
2410
+ }
2411
+ ),
2412
+ !needsOtp && /* @__PURE__ */ jsx("div", { style: { textAlign: "center", marginTop: "16px" }, children: /* @__PURE__ */ jsx(
2413
+ "button",
2414
+ {
2415
+ type: "button",
2416
+ onClick: toggleAuthMethod,
2417
+ disabled: isLoading,
2418
+ style: {
2419
+ background: "none",
2420
+ border: "none",
2421
+ color: "#007bff",
2422
+ cursor: "pointer",
2423
+ fontSize: "14px",
2424
+ fontWeight: 600
2425
+ },
2426
+ children: usePassword ? "Use email code instead" : "Use password instead"
2427
+ }
2428
+ ) }),
2429
+ needsOtp && /* @__PURE__ */ jsx("div", { style: { textAlign: "center", marginTop: "16px" }, children: /* @__PURE__ */ jsx(
2430
+ "button",
2431
+ {
2432
+ type: "button",
2433
+ onClick: () => {
2434
+ setNeedsOtp(false);
2435
+ setOtp("");
2436
+ setError(null);
2437
+ setSuccess(null);
2438
+ },
2439
+ disabled: isLoading,
2440
+ style: {
2441
+ background: "none",
2442
+ border: "none",
2443
+ color: "#007bff",
2444
+ cursor: "pointer",
2445
+ fontSize: "14px",
2446
+ fontWeight: 600
2447
+ },
2448
+ children: "Back to sign in"
2449
+ }
2450
+ ) })
2451
+ ] }) });
2452
+ };
2453
+ var SignUp = ({ redirectUrl, appearance }) => {
2454
+ const { signUp, isSignedIn } = useAuth();
2455
+ const [name, setName] = useState("");
2456
+ const [email, setEmail] = useState("");
2457
+ const [password, setPassword] = useState("");
2458
+ const [confirmPassword, setConfirmPassword] = useState("");
2459
+ const [showPassword, setShowPassword] = useState(false);
2460
+ const [isLoading, setIsLoading] = useState(false);
2461
+ const [error, setError] = useState(null);
2462
+ const [success, setSuccess] = useState(null);
2463
+ useEffect(() => {
2464
+ if (isSignedIn && redirectUrl) {
2465
+ const redirect = redirectUrl || process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_REGISTER || process.env.REACT_APP_AUTH_REDIRECT_AFTER_REGISTER || "/dashboard";
2466
+ const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
2467
+ window.location.href = `${baseUrl}${redirect}`;
2468
+ }
2469
+ }, [isSignedIn, redirectUrl]);
2470
+ const getPasswordStrength = (pwd) => {
2471
+ if (!pwd)
2472
+ return { strength: "weak", color: "#ddd" };
2473
+ let score = 0;
2474
+ if (pwd.length >= 6)
2475
+ score++;
2476
+ if (pwd.length >= 8)
2477
+ score++;
2478
+ if (/[a-z]/.test(pwd) && /[A-Z]/.test(pwd))
2479
+ score++;
2480
+ if (/\d/.test(pwd))
2481
+ score++;
2482
+ if (/[^a-zA-Z\d]/.test(pwd))
2483
+ score++;
2484
+ if (score <= 2)
2485
+ return { strength: "weak", color: "#f44" };
2486
+ if (score <= 3)
2487
+ return { strength: "medium", color: "#fa4" };
2488
+ return { strength: "strong", color: "#4f4" };
2489
+ };
2490
+ const passwordStrength = getPasswordStrength(password);
2491
+ const handleSubmit = async (e) => {
2492
+ e.preventDefault();
2493
+ setIsLoading(true);
2494
+ setError(null);
2495
+ setSuccess(null);
2496
+ if (password !== confirmPassword) {
2497
+ setError("Passwords do not match");
2498
+ setIsLoading(false);
2499
+ return;
2500
+ }
2501
+ if (password.length < 6) {
2502
+ setError("Password must be at least 6 characters");
2503
+ setIsLoading(false);
2504
+ return;
2505
+ }
2506
+ try {
2507
+ const response = await signUp({ name, email, password });
2508
+ if (response.success) {
2509
+ setSuccess("Registration successful! Please check your email to verify your account.");
2510
+ } else {
2511
+ setError(response.message || "Registration failed");
2512
+ }
2513
+ } catch (err) {
2514
+ setError(err instanceof Error ? err.message : "An error occurred");
2515
+ } finally {
2516
+ setIsLoading(false);
2517
+ }
2518
+ };
2519
+ return /* @__PURE__ */ jsx("div", { style: {
2520
+ maxWidth: "400px",
2521
+ margin: "0 auto",
2522
+ padding: "30px",
2523
+ borderRadius: "12px",
2524
+ boxShadow: "0 4px 20px rgba(0, 0, 0, 0.1)",
2525
+ backgroundColor: "#ffffff",
2526
+ border: "1px solid #eaeaea",
2527
+ ...appearance?.elements?.card
2528
+ }, children: /* @__PURE__ */ jsxs("form", { onSubmit: handleSubmit, children: [
2529
+ /* @__PURE__ */ jsx("h2", { style: {
2530
+ textAlign: "center",
2531
+ marginBottom: "24px",
2532
+ color: "#1f2937",
2533
+ fontSize: "24px",
2534
+ fontWeight: 600,
2535
+ ...appearance?.elements?.headerTitle
2536
+ }, children: "Create your account" }),
2537
+ error && /* @__PURE__ */ jsx("div", { style: {
2538
+ padding: "12px 16px",
2539
+ marginBottom: "20px",
2540
+ backgroundColor: "#fee",
2541
+ color: "#c33",
2542
+ border: "1px solid #fcc",
2543
+ borderRadius: "8px",
2544
+ fontSize: "14px"
2545
+ }, children: error }),
2546
+ success && /* @__PURE__ */ jsx("div", { style: {
2547
+ padding: "12px 16px",
2548
+ marginBottom: "20px",
2549
+ backgroundColor: "#efe",
2550
+ color: "#3c3",
2551
+ border: "1px solid #cfc",
2552
+ borderRadius: "8px",
2553
+ fontSize: "14px"
2554
+ }, children: success }),
2555
+ /* @__PURE__ */ jsxs("div", { style: { marginBottom: "20px" }, children: [
2556
+ /* @__PURE__ */ jsx("label", { htmlFor: "name", style: {
2557
+ display: "block",
2558
+ marginBottom: "8px",
2559
+ fontWeight: 500,
2560
+ color: "#374151",
2561
+ fontSize: "14px"
2562
+ }, children: "Full name" }),
2563
+ /* @__PURE__ */ jsx(
2564
+ "input",
2565
+ {
2566
+ id: "name",
2567
+ type: "text",
2568
+ value: name,
2569
+ onChange: (e) => setName(e.target.value),
2570
+ required: true,
2571
+ disabled: isLoading,
2572
+ style: {
2573
+ width: "100%",
2574
+ padding: "12px 16px",
2575
+ border: "1px solid #ddd",
2576
+ borderRadius: "8px",
2577
+ fontSize: "16px",
2578
+ boxSizing: "border-box",
2579
+ ...appearance?.elements?.formFieldInput
2580
+ },
2581
+ placeholder: "Enter your full name"
2582
+ }
2583
+ )
2584
+ ] }),
2585
+ /* @__PURE__ */ jsxs("div", { style: { marginBottom: "20px" }, children: [
2586
+ /* @__PURE__ */ jsx("label", { htmlFor: "email", style: {
2587
+ display: "block",
2588
+ marginBottom: "8px",
2589
+ fontWeight: 500,
2590
+ color: "#374151",
2591
+ fontSize: "14px"
2592
+ }, children: "Email" }),
2593
+ /* @__PURE__ */ jsx(
2594
+ "input",
2595
+ {
2596
+ id: "email",
2597
+ type: "email",
2598
+ value: email,
2599
+ onChange: (e) => setEmail(e.target.value),
2600
+ required: true,
2601
+ disabled: isLoading,
2602
+ style: {
2603
+ width: "100%",
2604
+ padding: "12px 16px",
2605
+ border: "1px solid #ddd",
2606
+ borderRadius: "8px",
2607
+ fontSize: "16px",
2608
+ boxSizing: "border-box",
2609
+ ...appearance?.elements?.formFieldInput
2610
+ },
2611
+ placeholder: "Enter your email"
2612
+ }
2613
+ )
2614
+ ] }),
2615
+ /* @__PURE__ */ jsxs("div", { style: { marginBottom: "20px", position: "relative" }, children: [
2616
+ /* @__PURE__ */ jsx("label", { htmlFor: "password", style: {
2617
+ display: "block",
2618
+ marginBottom: "8px",
2619
+ fontWeight: 500,
2620
+ color: "#374151",
2621
+ fontSize: "14px"
2622
+ }, children: "Password" }),
2623
+ /* @__PURE__ */ jsx(
2624
+ "input",
2625
+ {
2626
+ id: "password",
2627
+ type: showPassword ? "text" : "password",
2628
+ value: password,
2629
+ onChange: (e) => setPassword(e.target.value),
2630
+ required: true,
2631
+ disabled: isLoading,
2632
+ minLength: 6,
2633
+ style: {
2634
+ width: "100%",
2635
+ padding: "12px 16px",
2636
+ border: "1px solid #ddd",
2637
+ borderRadius: "8px",
2638
+ fontSize: "16px",
2639
+ boxSizing: "border-box",
2640
+ ...appearance?.elements?.formFieldInput
2641
+ },
2642
+ placeholder: "Create a password"
2643
+ }
2644
+ ),
2645
+ /* @__PURE__ */ jsx(
2646
+ "button",
2647
+ {
2648
+ type: "button",
2649
+ onClick: () => setShowPassword(!showPassword),
2650
+ style: {
2651
+ position: "absolute",
2652
+ right: "12px",
2653
+ top: "38px",
2654
+ background: "none",
2655
+ border: "none",
2656
+ cursor: "pointer",
2657
+ color: "#666",
2658
+ fontSize: "14px"
2659
+ },
2660
+ children: showPassword ? "Hide" : "Show"
2661
+ }
2662
+ ),
2663
+ password && /* @__PURE__ */ jsxs("div", { style: { marginTop: "8px" }, children: [
2664
+ /* @__PURE__ */ jsx("div", { style: {
2665
+ height: "4px",
2666
+ backgroundColor: "#eee",
2667
+ borderRadius: "2px",
2668
+ overflow: "hidden"
2669
+ }, children: /* @__PURE__ */ jsx("div", { style: {
2670
+ height: "100%",
2671
+ width: passwordStrength.strength === "weak" ? "33%" : passwordStrength.strength === "medium" ? "66%" : "100%",
2672
+ backgroundColor: passwordStrength.color,
2673
+ transition: "all 0.3s ease"
2674
+ } }) }),
2675
+ /* @__PURE__ */ jsxs("p", { style: {
2676
+ fontSize: "12px",
2677
+ color: passwordStrength.color,
2678
+ marginTop: "4px",
2679
+ textTransform: "capitalize"
2680
+ }, children: [
2681
+ passwordStrength.strength,
2682
+ " password"
2683
+ ] })
2684
+ ] })
2685
+ ] }),
2686
+ /* @__PURE__ */ jsxs("div", { style: { marginBottom: "20px" }, children: [
2687
+ /* @__PURE__ */ jsx("label", { htmlFor: "confirmPassword", style: {
2688
+ display: "block",
2689
+ marginBottom: "8px",
2690
+ fontWeight: 500,
2691
+ color: "#374151",
2692
+ fontSize: "14px"
2693
+ }, children: "Confirm password" }),
2694
+ /* @__PURE__ */ jsx(
2695
+ "input",
2696
+ {
2697
+ id: "confirmPassword",
2698
+ type: showPassword ? "text" : "password",
2699
+ value: confirmPassword,
2700
+ onChange: (e) => setConfirmPassword(e.target.value),
2701
+ required: true,
2702
+ disabled: isLoading,
2703
+ style: {
2704
+ width: "100%",
2705
+ padding: "12px 16px",
2706
+ border: "1px solid #ddd",
2707
+ borderRadius: "8px",
2708
+ fontSize: "16px",
2709
+ boxSizing: "border-box",
2710
+ ...appearance?.elements?.formFieldInput
2711
+ },
2712
+ placeholder: "Confirm your password"
2713
+ }
2714
+ )
2715
+ ] }),
2716
+ /* @__PURE__ */ jsx(
2717
+ "button",
2718
+ {
2719
+ type: "submit",
2720
+ disabled: isLoading,
2721
+ style: {
2722
+ width: "100%",
2723
+ padding: "14px",
2724
+ backgroundColor: "#007bff",
2725
+ color: "white",
2726
+ border: "none",
2727
+ borderRadius: "8px",
2728
+ fontSize: "16px",
2729
+ fontWeight: 600,
2730
+ cursor: "pointer",
2731
+ transition: "all 0.2s ease",
2732
+ ...appearance?.elements?.formButtonPrimary
2733
+ },
2734
+ children: isLoading ? "Creating account..." : "Sign up"
2735
+ }
2736
+ )
2737
+ ] }) });
2738
+ };
2739
+ var SignOut = ({ redirectUrl }) => {
2740
+ const { signOut } = useAuth();
2741
+ useEffect(() => {
2742
+ const performSignOut = async () => {
2743
+ await signOut();
2744
+ const redirect = redirectUrl || process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_LOGOUT || process.env.REACT_APP_AUTH_REDIRECT_AFTER_LOGOUT || "/";
2745
+ const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
2746
+ window.location.href = `${baseUrl}${redirect}`;
2747
+ };
2748
+ performSignOut();
2749
+ }, [signOut, redirectUrl]);
2750
+ return /* @__PURE__ */ jsx("div", { style: { textAlign: "center", padding: "40px" }, children: /* @__PURE__ */ jsx("div", { children: "Signing out..." }) });
2751
+ };
2752
+ var UserButton = ({ showName = false, appearance }) => {
2753
+ const { user, signOut } = useAuth();
2754
+ const [isOpen, setIsOpen] = useState(false);
2755
+ const dropdownRef = useRef(null);
2756
+ useEffect(() => {
2757
+ const handleClickOutside = (event) => {
2758
+ if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
2759
+ setIsOpen(false);
2760
+ }
2761
+ };
2762
+ document.addEventListener("mousedown", handleClickOutside);
2763
+ return () => document.removeEventListener("mousedown", handleClickOutside);
2764
+ }, []);
2765
+ if (!user)
2766
+ return null;
2767
+ const getInitials = (name) => {
2768
+ return name.split(" ").map((n) => n[0]).join("").toUpperCase().slice(0, 2);
2769
+ };
2770
+ const handleSignOut = async () => {
2771
+ await signOut();
2772
+ const redirect = process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_LOGOUT || process.env.REACT_APP_AUTH_REDIRECT_AFTER_LOGOUT || "/";
2773
+ const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
2774
+ window.location.href = `${baseUrl}${redirect}`;
2775
+ };
2776
+ return /* @__PURE__ */ jsxs("div", { style: { position: "relative", ...appearance?.elements?.userButtonBox }, ref: dropdownRef, children: [
2777
+ /* @__PURE__ */ jsxs(
2778
+ "button",
2779
+ {
2780
+ onClick: () => setIsOpen(!isOpen),
2781
+ style: {
2782
+ display: "flex",
2783
+ alignItems: "center",
2784
+ gap: "8px",
2785
+ padding: "6px",
2786
+ backgroundColor: "transparent",
2787
+ border: "none",
2788
+ borderRadius: "8px",
2789
+ cursor: "pointer",
2790
+ transition: "background-color 0.2s",
2791
+ ...appearance?.elements?.userButtonTrigger
2792
+ },
2793
+ onMouseEnter: (e) => {
2794
+ e.currentTarget.style.backgroundColor = "#f5f5f5";
2795
+ },
2796
+ onMouseLeave: (e) => {
2797
+ e.currentTarget.style.backgroundColor = "transparent";
2798
+ },
2799
+ children: [
2800
+ /* @__PURE__ */ jsx("div", { style: {
2801
+ width: "36px",
2802
+ height: "36px",
2803
+ borderRadius: "50%",
2804
+ backgroundColor: "#007bff",
2805
+ color: "white",
2806
+ display: "flex",
2807
+ alignItems: "center",
2808
+ justifyContent: "center",
2809
+ fontSize: "14px",
2810
+ fontWeight: 600
2811
+ }, children: getInitials(user.name) }),
2812
+ showName && /* @__PURE__ */ jsx("span", { style: { fontSize: "14px", fontWeight: 500, color: "#333" }, children: user.name })
2813
+ ]
2814
+ }
2815
+ ),
2816
+ isOpen && /* @__PURE__ */ jsxs("div", { style: {
2817
+ position: "absolute",
2818
+ top: "100%",
2819
+ right: 0,
2820
+ marginTop: "8px",
2821
+ width: "240px",
2822
+ backgroundColor: "white",
2823
+ borderRadius: "12px",
2824
+ boxShadow: "0 4px 20px rgba(0, 0, 0, 0.15)",
2825
+ border: "1px solid #eaeaea",
2826
+ zIndex: 1e3,
2827
+ ...appearance?.elements?.userButtonPopoverCard
2828
+ }, children: [
2829
+ /* @__PURE__ */ jsx("div", { style: {
2830
+ padding: "16px",
2831
+ borderBottom: "1px solid #eee"
2832
+ }, children: /* @__PURE__ */ jsxs("div", { style: {
2833
+ display: "flex",
2834
+ alignItems: "center",
2835
+ gap: "12px"
2836
+ }, children: [
2837
+ /* @__PURE__ */ jsx("div", { style: {
2838
+ width: "48px",
2839
+ height: "48px",
2840
+ borderRadius: "50%",
2841
+ backgroundColor: "#007bff",
2842
+ color: "white",
2843
+ display: "flex",
2844
+ alignItems: "center",
2845
+ justifyContent: "center",
2846
+ fontSize: "18px",
2847
+ fontWeight: 600
2848
+ }, children: getInitials(user.name) }),
2849
+ /* @__PURE__ */ jsxs("div", { style: { flex: 1, minWidth: 0 }, children: [
2850
+ /* @__PURE__ */ jsx("div", { style: {
2851
+ fontSize: "14px",
2852
+ fontWeight: 600,
2853
+ color: "#333",
2854
+ overflow: "hidden",
2855
+ textOverflow: "ellipsis",
2856
+ whiteSpace: "nowrap"
2857
+ }, children: user.name }),
2858
+ /* @__PURE__ */ jsx("div", { style: {
2859
+ fontSize: "12px",
2860
+ color: "#666",
2861
+ overflow: "hidden",
2862
+ textOverflow: "ellipsis",
2863
+ whiteSpace: "nowrap"
2864
+ }, children: user.email })
2865
+ ] })
2866
+ ] }) }),
2867
+ /* @__PURE__ */ jsx("div", { style: { padding: "8px" }, children: /* @__PURE__ */ jsx(
2868
+ "button",
2869
+ {
2870
+ onClick: handleSignOut,
2871
+ style: {
2872
+ width: "100%",
2873
+ padding: "10px 16px",
2874
+ backgroundColor: "transparent",
2875
+ border: "none",
2876
+ borderRadius: "8px",
2877
+ textAlign: "left",
2878
+ cursor: "pointer",
2879
+ fontSize: "14px",
2880
+ color: "#333",
2881
+ fontWeight: 500,
2882
+ transition: "background-color 0.2s"
2883
+ },
2884
+ onMouseEnter: (e) => {
2885
+ e.currentTarget.style.backgroundColor = "#f5f5f5";
2886
+ },
2887
+ onMouseLeave: (e) => {
2888
+ e.currentTarget.style.backgroundColor = "transparent";
2889
+ },
2890
+ children: "Sign out"
2891
+ }
2892
+ ) })
2893
+ ] })
2894
+ ] });
2895
+ };
2896
+ var ProtectedRoute = ({
2897
+ children,
2898
+ fallback,
2899
+ redirectTo
2900
+ }) => {
2901
+ const { isSignedIn, isLoaded } = useAuth();
2902
+ useEffect(() => {
2903
+ if (isLoaded && !isSignedIn) {
2904
+ const loginPath = redirectTo || process.env.NEXT_PUBLIC_AUTH_REDIRECT_TO_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_TO_LOGIN || "/auth/login";
2905
+ const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
2906
+ window.location.href = `${baseUrl}${loginPath}`;
2907
+ }
2908
+ }, [isSignedIn, isLoaded, redirectTo]);
2909
+ if (!isLoaded) {
2910
+ return fallback || /* @__PURE__ */ jsx("div", { style: {
2911
+ display: "flex",
2912
+ justifyContent: "center",
2913
+ alignItems: "center",
2914
+ minHeight: "100vh"
2915
+ }, children: /* @__PURE__ */ jsx("div", { children: "Loading..." }) });
2916
+ }
2917
+ if (!isSignedIn) {
2918
+ return fallback || null;
2919
+ }
2920
+ return /* @__PURE__ */ jsx(Fragment, { children });
2921
+ };
2922
+ var PublicRoute = ({
2923
+ children,
2924
+ redirectTo
2925
+ }) => {
2926
+ const { isSignedIn, isLoaded } = useAuth();
2927
+ useEffect(() => {
2928
+ if (isLoaded && isSignedIn) {
2929
+ const dashboardPath = redirectTo || process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_AFTER_LOGIN || "/dashboard";
2930
+ const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
2931
+ window.location.href = `${baseUrl}${dashboardPath}`;
2932
+ }
2933
+ }, [isSignedIn, isLoaded, redirectTo]);
2934
+ if (!isLoaded) {
2935
+ return /* @__PURE__ */ jsx("div", { style: {
2936
+ display: "flex",
2937
+ justifyContent: "center",
2938
+ alignItems: "center",
2939
+ minHeight: "100vh"
2940
+ }, children: /* @__PURE__ */ jsx("div", { children: "Loading..." }) });
2941
+ }
2942
+ if (isSignedIn) {
2943
+ return null;
2944
+ }
2945
+ return /* @__PURE__ */ jsx(Fragment, { children });
2946
+ };
2947
+ var VerifyEmail = ({ token, onSuccess, onError }) => {
2948
+ const { verifyEmailToken } = useAuth();
2949
+ const [status, setStatus] = useState("loading");
2950
+ const [message, setMessage] = useState("");
2951
+ useEffect(() => {
2952
+ const verify = async () => {
2953
+ const verifyToken = token || (typeof window !== "undefined" ? new URLSearchParams(window.location.search).get("token") : null);
2954
+ if (!verifyToken) {
2955
+ setStatus("error");
2956
+ setMessage("No verification token provided");
2957
+ onError?.("No verification token provided");
2958
+ return;
2959
+ }
2960
+ try {
2961
+ const response = await verifyEmailToken(verifyToken);
2962
+ if (response.success) {
2963
+ setStatus("success");
2964
+ setMessage("Email verified successfully! Redirecting...");
2965
+ onSuccess?.();
2966
+ setTimeout(() => {
2967
+ const redirect = process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_VERIFY || process.env.REACT_APP_AUTH_REDIRECT_AFTER_VERIFY || "/dashboard";
2968
+ const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
2969
+ window.location.href = `${baseUrl}${redirect}`;
2970
+ }, 2e3);
2971
+ } else {
2972
+ setStatus("error");
2973
+ setMessage(response.message || "Verification failed");
2974
+ onError?.(response.message || "Verification failed");
2975
+ }
2976
+ } catch (err) {
2977
+ setStatus("error");
2978
+ const errorMsg = err instanceof Error ? err.message : "An error occurred";
2979
+ setMessage(errorMsg);
2980
+ onError?.(errorMsg);
2981
+ }
2982
+ };
2983
+ verify();
2984
+ }, [token, verifyEmailToken, onSuccess, onError]);
2985
+ return /* @__PURE__ */ jsxs("div", { style: {
2986
+ maxWidth: "400px",
2987
+ margin: "40px auto",
2988
+ padding: "30px",
2989
+ borderRadius: "12px",
2990
+ boxShadow: "0 4px 20px rgba(0, 0, 0, 0.1)",
2991
+ backgroundColor: "#ffffff",
2992
+ border: "1px solid #eaeaea",
2993
+ textAlign: "center"
2994
+ }, children: [
2995
+ status === "loading" && /* @__PURE__ */ jsxs(Fragment, { children: [
2996
+ /* @__PURE__ */ jsx("div", { style: {
2997
+ width: "48px",
2998
+ height: "48px",
2999
+ margin: "0 auto 20px",
3000
+ border: "4px solid #f3f3f3",
3001
+ borderTop: "4px solid #007bff",
3002
+ borderRadius: "50%",
3003
+ animation: "spin 1s linear infinite"
3004
+ } }),
3005
+ /* @__PURE__ */ jsx("style", { children: `
3006
+ @keyframes spin {
3007
+ 0% { transform: rotate(0deg); }
3008
+ 100% { transform: rotate(360deg); }
3009
+ }
3010
+ ` }),
3011
+ /* @__PURE__ */ jsx("h2", { style: {
3012
+ fontSize: "20px",
3013
+ fontWeight: 600,
3014
+ color: "#333",
3015
+ marginBottom: "12px"
3016
+ }, children: "Verifying your email..." }),
3017
+ /* @__PURE__ */ jsx("p", { style: { fontSize: "14px", color: "#666" }, children: "Please wait while we verify your email address." })
3018
+ ] }),
3019
+ status === "success" && /* @__PURE__ */ jsxs(Fragment, { children: [
3020
+ /* @__PURE__ */ jsx("div", { style: {
3021
+ width: "64px",
3022
+ height: "64px",
3023
+ margin: "0 auto 20px",
3024
+ backgroundColor: "#4caf50",
3025
+ borderRadius: "50%",
3026
+ display: "flex",
3027
+ alignItems: "center",
3028
+ justifyContent: "center"
3029
+ }, children: /* @__PURE__ */ jsx("svg", { width: "32", height: "32", viewBox: "0 0 24 24", fill: "none", stroke: "white", strokeWidth: "3", children: /* @__PURE__ */ jsx("polyline", { points: "20 6 9 17 4 12" }) }) }),
3030
+ /* @__PURE__ */ jsx("h2", { style: {
3031
+ fontSize: "20px",
3032
+ fontWeight: 600,
3033
+ color: "#333",
3034
+ marginBottom: "12px"
3035
+ }, children: "Email Verified!" }),
3036
+ /* @__PURE__ */ jsx("p", { style: { fontSize: "14px", color: "#666" }, children: message })
3037
+ ] }),
3038
+ status === "error" && /* @__PURE__ */ jsxs(Fragment, { children: [
3039
+ /* @__PURE__ */ jsx("div", { style: {
3040
+ width: "64px",
3041
+ height: "64px",
3042
+ margin: "0 auto 20px",
3043
+ backgroundColor: "#f44336",
3044
+ borderRadius: "50%",
3045
+ display: "flex",
3046
+ alignItems: "center",
3047
+ justifyContent: "center"
3048
+ }, children: /* @__PURE__ */ jsxs("svg", { width: "32", height: "32", viewBox: "0 0 24 24", fill: "none", stroke: "white", strokeWidth: "3", children: [
3049
+ /* @__PURE__ */ jsx("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
3050
+ /* @__PURE__ */ jsx("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
3051
+ ] }) }),
3052
+ /* @__PURE__ */ jsx("h2", { style: {
3053
+ fontSize: "20px",
3054
+ fontWeight: 600,
3055
+ color: "#333",
3056
+ marginBottom: "12px"
3057
+ }, children: "Verification Failed" }),
3058
+ /* @__PURE__ */ jsx("p", { style: { fontSize: "14px", color: "#666", marginBottom: "20px" }, children: message }),
3059
+ /* @__PURE__ */ jsx(
3060
+ "button",
3061
+ {
3062
+ onClick: () => {
3063
+ const loginPath = process.env.NEXT_PUBLIC_AUTH_REDIRECT_TO_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_TO_LOGIN || "/auth/login";
3064
+ const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
3065
+ window.location.href = `${baseUrl}${loginPath}`;
3066
+ },
3067
+ style: {
3068
+ padding: "10px 20px",
3069
+ backgroundColor: "#007bff",
3070
+ color: "white",
3071
+ border: "none",
3072
+ borderRadius: "8px",
3073
+ fontSize: "14px",
3074
+ fontWeight: 600,
3075
+ cursor: "pointer"
3076
+ },
3077
+ children: "Go to Login"
3078
+ }
3079
+ )
3080
+ ] })
3081
+ ] });
3082
+ };
3083
+ var ForgotPassword = ({ appearance }) => {
3084
+ const { forgotPassword } = useAuth();
3085
+ const [email, setEmail] = useState("");
3086
+ const [isLoading, setIsLoading] = useState(false);
3087
+ const [error, setError] = useState(null);
3088
+ const [success, setSuccess] = useState(null);
3089
+ const handleSubmit = async (e) => {
3090
+ e.preventDefault();
3091
+ setIsLoading(true);
3092
+ setError(null);
3093
+ setSuccess(null);
3094
+ try {
3095
+ const response = await forgotPassword(email);
3096
+ if (response.success) {
3097
+ setSuccess("Password reset link sent! Please check your email.");
3098
+ setEmail("");
3099
+ } else {
3100
+ setError(response.message || "Failed to send reset link");
3101
+ }
3102
+ } catch (err) {
3103
+ setError(err instanceof Error ? err.message : "An error occurred");
3104
+ } finally {
3105
+ setIsLoading(false);
3106
+ }
3107
+ };
3108
+ return /* @__PURE__ */ jsx("div", { style: {
3109
+ maxWidth: "400px",
3110
+ margin: "0 auto",
3111
+ padding: "30px",
3112
+ borderRadius: "12px",
3113
+ boxShadow: "0 4px 20px rgba(0, 0, 0, 0.1)",
3114
+ backgroundColor: "#ffffff",
3115
+ border: "1px solid #eaeaea",
3116
+ ...appearance?.elements?.card
3117
+ }, children: /* @__PURE__ */ jsxs("form", { onSubmit: handleSubmit, children: [
3118
+ /* @__PURE__ */ jsx("h2", { style: {
3119
+ textAlign: "center",
3120
+ marginBottom: "12px",
3121
+ color: "#1f2937",
3122
+ fontSize: "24px",
3123
+ fontWeight: 600,
3124
+ ...appearance?.elements?.headerTitle
3125
+ }, children: "Forgot password?" }),
3126
+ /* @__PURE__ */ jsx("p", { style: {
3127
+ textAlign: "center",
3128
+ marginBottom: "24px",
3129
+ color: "#666",
3130
+ fontSize: "14px"
3131
+ }, children: "Enter your email address and we'll send you a link to reset your password." }),
3132
+ error && /* @__PURE__ */ jsx("div", { style: {
3133
+ padding: "12px 16px",
3134
+ marginBottom: "20px",
3135
+ backgroundColor: "#fee",
3136
+ color: "#c33",
3137
+ border: "1px solid #fcc",
3138
+ borderRadius: "8px",
3139
+ fontSize: "14px"
3140
+ }, children: error }),
3141
+ success && /* @__PURE__ */ jsx("div", { style: {
3142
+ padding: "12px 16px",
3143
+ marginBottom: "20px",
3144
+ backgroundColor: "#efe",
3145
+ color: "#3c3",
3146
+ border: "1px solid #cfc",
3147
+ borderRadius: "8px",
3148
+ fontSize: "14px"
3149
+ }, children: success }),
3150
+ /* @__PURE__ */ jsxs("div", { style: { marginBottom: "20px" }, children: [
3151
+ /* @__PURE__ */ jsx("label", { htmlFor: "email", style: {
3152
+ display: "block",
3153
+ marginBottom: "8px",
3154
+ fontWeight: 500,
3155
+ color: "#374151",
3156
+ fontSize: "14px"
3157
+ }, children: "Email" }),
3158
+ /* @__PURE__ */ jsx(
3159
+ "input",
3160
+ {
3161
+ id: "email",
3162
+ type: "email",
3163
+ value: email,
3164
+ onChange: (e) => setEmail(e.target.value),
3165
+ required: true,
3166
+ disabled: isLoading,
3167
+ style: {
3168
+ width: "100%",
3169
+ padding: "12px 16px",
3170
+ border: "1px solid #ddd",
3171
+ borderRadius: "8px",
3172
+ fontSize: "16px",
3173
+ boxSizing: "border-box",
3174
+ ...appearance?.elements?.formFieldInput
3175
+ },
3176
+ placeholder: "Enter your email"
3177
+ }
3178
+ )
3179
+ ] }),
3180
+ /* @__PURE__ */ jsx(
3181
+ "button",
3182
+ {
3183
+ type: "submit",
3184
+ disabled: isLoading,
3185
+ style: {
3186
+ width: "100%",
3187
+ padding: "14px",
3188
+ backgroundColor: "#007bff",
3189
+ color: "white",
3190
+ border: "none",
3191
+ borderRadius: "8px",
3192
+ fontSize: "16px",
3193
+ fontWeight: 600,
3194
+ cursor: "pointer",
3195
+ transition: "all 0.2s ease",
3196
+ marginBottom: "16px",
3197
+ ...appearance?.elements?.formButtonPrimary
3198
+ },
3199
+ children: isLoading ? "Sending..." : "Send reset link"
3200
+ }
3201
+ ),
3202
+ /* @__PURE__ */ jsx("div", { style: { textAlign: "center" }, children: /* @__PURE__ */ jsx(
3203
+ "button",
3204
+ {
3205
+ type: "button",
3206
+ onClick: () => {
3207
+ const loginPath = process.env.NEXT_PUBLIC_AUTH_REDIRECT_TO_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_TO_LOGIN || "/auth/login";
3208
+ const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
3209
+ window.location.href = `${baseUrl}${loginPath}`;
3210
+ },
3211
+ disabled: isLoading,
3212
+ style: {
3213
+ background: "none",
3214
+ border: "none",
3215
+ color: "#007bff",
3216
+ cursor: "pointer",
3217
+ fontSize: "14px",
3218
+ fontWeight: 600
3219
+ },
3220
+ children: "Back to sign in"
3221
+ }
3222
+ ) })
3223
+ ] }) });
3224
+ };
3225
+ var ResetPassword = ({ token, appearance }) => {
3226
+ const { resetPassword } = useAuth();
3227
+ const [resetToken, setResetToken] = useState(token || "");
3228
+ const [password, setPassword] = useState("");
3229
+ const [confirmPassword, setConfirmPassword] = useState("");
3230
+ const [showPassword, setShowPassword] = useState(false);
3231
+ const [isLoading, setIsLoading] = useState(false);
3232
+ const [error, setError] = useState(null);
3233
+ const [success, setSuccess] = useState(false);
3234
+ useEffect(() => {
3235
+ if (!resetToken && typeof window !== "undefined") {
3236
+ const urlToken = new URLSearchParams(window.location.search).get("token");
3237
+ if (urlToken) {
3238
+ setResetToken(urlToken);
3239
+ }
3240
+ }
3241
+ }, [resetToken]);
3242
+ const getPasswordStrength = (pwd) => {
3243
+ if (!pwd)
3244
+ return { strength: "weak", color: "#ddd" };
3245
+ let score = 0;
3246
+ if (pwd.length >= 6)
3247
+ score++;
3248
+ if (pwd.length >= 8)
3249
+ score++;
3250
+ if (/[a-z]/.test(pwd) && /[A-Z]/.test(pwd))
3251
+ score++;
3252
+ if (/\d/.test(pwd))
3253
+ score++;
3254
+ if (/[^a-zA-Z\d]/.test(pwd))
3255
+ score++;
3256
+ if (score <= 2)
3257
+ return { strength: "weak", color: "#f44" };
3258
+ if (score <= 3)
3259
+ return { strength: "medium", color: "#fa4" };
3260
+ return { strength: "strong", color: "#4f4" };
3261
+ };
3262
+ const passwordStrength = getPasswordStrength(password);
3263
+ const handleSubmit = async (e) => {
3264
+ e.preventDefault();
3265
+ setIsLoading(true);
3266
+ setError(null);
3267
+ if (password !== confirmPassword) {
3268
+ setError("Passwords do not match");
3269
+ setIsLoading(false);
3270
+ return;
3271
+ }
3272
+ if (password.length < 6) {
3273
+ setError("Password must be at least 6 characters");
3274
+ setIsLoading(false);
3275
+ return;
3276
+ }
3277
+ if (!resetToken) {
3278
+ setError("Invalid reset token");
3279
+ setIsLoading(false);
3280
+ return;
3281
+ }
3282
+ try {
3283
+ const response = await resetPassword(resetToken, password);
3284
+ if (response.success) {
3285
+ setSuccess(true);
3286
+ setTimeout(() => {
3287
+ const loginPath = process.env.NEXT_PUBLIC_AUTH_REDIRECT_TO_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_TO_LOGIN || "/auth/login";
3288
+ const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
3289
+ window.location.href = `${baseUrl}${loginPath}`;
3290
+ }, 2e3);
3291
+ } else {
3292
+ setError(response.message || "Failed to reset password");
3293
+ }
3294
+ } catch (err) {
3295
+ setError(err instanceof Error ? err.message : "An error occurred");
3296
+ } finally {
3297
+ setIsLoading(false);
3298
+ }
3299
+ };
3300
+ if (success) {
3301
+ return /* @__PURE__ */ jsxs("div", { style: {
3302
+ maxWidth: "400px",
3303
+ margin: "40px auto",
3304
+ padding: "30px",
3305
+ borderRadius: "12px",
3306
+ boxShadow: "0 4px 20px rgba(0, 0, 0, 0.1)",
3307
+ backgroundColor: "#ffffff",
3308
+ border: "1px solid #eaeaea",
3309
+ textAlign: "center"
3310
+ }, children: [
3311
+ /* @__PURE__ */ jsx("div", { style: {
3312
+ width: "64px",
3313
+ height: "64px",
3314
+ margin: "0 auto 20px",
3315
+ backgroundColor: "#4caf50",
3316
+ borderRadius: "50%",
3317
+ display: "flex",
3318
+ alignItems: "center",
3319
+ justifyContent: "center"
3320
+ }, children: /* @__PURE__ */ jsx("svg", { width: "32", height: "32", viewBox: "0 0 24 24", fill: "none", stroke: "white", strokeWidth: "3", children: /* @__PURE__ */ jsx("polyline", { points: "20 6 9 17 4 12" }) }) }),
3321
+ /* @__PURE__ */ jsx("h2", { style: {
3322
+ fontSize: "20px",
3323
+ fontWeight: 600,
3324
+ color: "#333",
3325
+ marginBottom: "12px"
3326
+ }, children: "Password Reset Successful!" }),
3327
+ /* @__PURE__ */ jsx("p", { style: { fontSize: "14px", color: "#666" }, children: "Your password has been reset. Redirecting to login..." })
3328
+ ] });
3329
+ }
3330
+ return /* @__PURE__ */ jsx("div", { style: {
3331
+ maxWidth: "400px",
3332
+ margin: "0 auto",
3333
+ padding: "30px",
3334
+ borderRadius: "12px",
3335
+ boxShadow: "0 4px 20px rgba(0, 0, 0, 0.1)",
3336
+ backgroundColor: "#ffffff",
3337
+ border: "1px solid #eaeaea",
3338
+ ...appearance?.elements?.card
3339
+ }, children: /* @__PURE__ */ jsxs("form", { onSubmit: handleSubmit, children: [
3340
+ /* @__PURE__ */ jsx("h2", { style: {
3341
+ textAlign: "center",
3342
+ marginBottom: "12px",
3343
+ color: "#1f2937",
3344
+ fontSize: "24px",
3345
+ fontWeight: 600,
3346
+ ...appearance?.elements?.headerTitle
3347
+ }, children: "Reset your password" }),
3348
+ /* @__PURE__ */ jsx("p", { style: {
3349
+ textAlign: "center",
3350
+ marginBottom: "24px",
3351
+ color: "#666",
3352
+ fontSize: "14px"
3353
+ }, children: "Enter your new password below." }),
3354
+ error && /* @__PURE__ */ jsx("div", { style: {
3355
+ padding: "12px 16px",
3356
+ marginBottom: "20px",
3357
+ backgroundColor: "#fee",
3358
+ color: "#c33",
3359
+ border: "1px solid #fcc",
3360
+ borderRadius: "8px",
3361
+ fontSize: "14px"
3362
+ }, children: error }),
3363
+ /* @__PURE__ */ jsxs("div", { style: { marginBottom: "20px", position: "relative" }, children: [
3364
+ /* @__PURE__ */ jsx("label", { htmlFor: "password", style: {
3365
+ display: "block",
3366
+ marginBottom: "8px",
3367
+ fontWeight: 500,
3368
+ color: "#374151",
3369
+ fontSize: "14px"
3370
+ }, children: "New password" }),
3371
+ /* @__PURE__ */ jsx(
3372
+ "input",
3373
+ {
3374
+ id: "password",
3375
+ type: showPassword ? "text" : "password",
3376
+ value: password,
3377
+ onChange: (e) => setPassword(e.target.value),
3378
+ required: true,
3379
+ disabled: isLoading,
3380
+ minLength: 6,
3381
+ style: {
3382
+ width: "100%",
3383
+ padding: "12px 16px",
3384
+ border: "1px solid #ddd",
3385
+ borderRadius: "8px",
3386
+ fontSize: "16px",
3387
+ boxSizing: "border-box",
3388
+ ...appearance?.elements?.formFieldInput
3389
+ },
3390
+ placeholder: "Enter new password"
3391
+ }
3392
+ ),
3393
+ /* @__PURE__ */ jsx(
3394
+ "button",
3395
+ {
3396
+ type: "button",
3397
+ onClick: () => setShowPassword(!showPassword),
3398
+ style: {
3399
+ position: "absolute",
3400
+ right: "12px",
3401
+ top: "38px",
3402
+ background: "none",
3403
+ border: "none",
3404
+ cursor: "pointer",
3405
+ color: "#666",
3406
+ fontSize: "14px"
3407
+ },
3408
+ children: showPassword ? "Hide" : "Show"
3409
+ }
3410
+ ),
3411
+ password && /* @__PURE__ */ jsxs("div", { style: { marginTop: "8px" }, children: [
3412
+ /* @__PURE__ */ jsx("div", { style: {
3413
+ height: "4px",
3414
+ backgroundColor: "#eee",
3415
+ borderRadius: "2px",
3416
+ overflow: "hidden"
3417
+ }, children: /* @__PURE__ */ jsx("div", { style: {
3418
+ height: "100%",
3419
+ width: passwordStrength.strength === "weak" ? "33%" : passwordStrength.strength === "medium" ? "66%" : "100%",
3420
+ backgroundColor: passwordStrength.color,
3421
+ transition: "all 0.3s ease"
3422
+ } }) }),
3423
+ /* @__PURE__ */ jsxs("p", { style: {
3424
+ fontSize: "12px",
3425
+ color: passwordStrength.color,
3426
+ marginTop: "4px",
3427
+ textTransform: "capitalize"
3428
+ }, children: [
3429
+ passwordStrength.strength,
3430
+ " password"
3431
+ ] })
3432
+ ] })
3433
+ ] }),
3434
+ /* @__PURE__ */ jsxs("div", { style: { marginBottom: "20px" }, children: [
3435
+ /* @__PURE__ */ jsx("label", { htmlFor: "confirmPassword", style: {
3436
+ display: "block",
3437
+ marginBottom: "8px",
3438
+ fontWeight: 500,
3439
+ color: "#374151",
3440
+ fontSize: "14px"
3441
+ }, children: "Confirm password" }),
3442
+ /* @__PURE__ */ jsx(
3443
+ "input",
3444
+ {
3445
+ id: "confirmPassword",
3446
+ type: showPassword ? "text" : "password",
3447
+ value: confirmPassword,
3448
+ onChange: (e) => setConfirmPassword(e.target.value),
3449
+ required: true,
3450
+ disabled: isLoading,
3451
+ style: {
3452
+ width: "100%",
3453
+ padding: "12px 16px",
3454
+ border: "1px solid #ddd",
3455
+ borderRadius: "8px",
3456
+ fontSize: "16px",
3457
+ boxSizing: "border-box",
3458
+ ...appearance?.elements?.formFieldInput
3459
+ },
3460
+ placeholder: "Confirm new password"
3461
+ }
3462
+ )
3463
+ ] }),
3464
+ /* @__PURE__ */ jsx(
3465
+ "button",
3466
+ {
3467
+ type: "submit",
3468
+ disabled: isLoading,
3469
+ style: {
3470
+ width: "100%",
3471
+ padding: "14px",
3472
+ backgroundColor: "#007bff",
3473
+ color: "white",
3474
+ border: "none",
3475
+ borderRadius: "8px",
3476
+ fontSize: "16px",
3477
+ fontWeight: 600,
3478
+ cursor: "pointer",
3479
+ transition: "all 0.2s ease",
3480
+ ...appearance?.elements?.formButtonPrimary
3481
+ },
3482
+ children: isLoading ? "Resetting..." : "Reset password"
3483
+ }
3484
+ )
3485
+ ] }) });
3486
+ };
3487
+ var ChangePassword = ({ onSuccess, appearance }) => {
3488
+ const { changePassword } = useAuth();
3489
+ const [oldPassword, setOldPassword] = useState("");
3490
+ const [newPassword, setNewPassword] = useState("");
3491
+ const [confirmPassword, setConfirmPassword] = useState("");
3492
+ const [showPasswords, setShowPasswords] = useState(false);
3493
+ const [isLoading, setIsLoading] = useState(false);
3494
+ const [error, setError] = useState(null);
3495
+ const [success, setSuccess] = useState(false);
3496
+ const getPasswordStrength = (pwd) => {
3497
+ if (!pwd)
3498
+ return { strength: "weak", color: "#ddd" };
3499
+ let score = 0;
3500
+ if (pwd.length >= 6)
3501
+ score++;
3502
+ if (pwd.length >= 8)
3503
+ score++;
3504
+ if (/[a-z]/.test(pwd) && /[A-Z]/.test(pwd))
3505
+ score++;
3506
+ if (/\d/.test(pwd))
3507
+ score++;
3508
+ if (/[^a-zA-Z\d]/.test(pwd))
3509
+ score++;
3510
+ if (score <= 2)
3511
+ return { strength: "weak", color: "#f44" };
3512
+ if (score <= 3)
3513
+ return { strength: "medium", color: "#fa4" };
3514
+ return { strength: "strong", color: "#4f4" };
3515
+ };
3516
+ const passwordStrength = getPasswordStrength(newPassword);
3517
+ const handleSubmit = async (e) => {
3518
+ e.preventDefault();
3519
+ setIsLoading(true);
3520
+ setError(null);
3521
+ setSuccess(false);
3522
+ if (newPassword !== confirmPassword) {
3523
+ setError("New passwords do not match");
3524
+ setIsLoading(false);
3525
+ return;
3526
+ }
3527
+ if (newPassword.length < 6) {
3528
+ setError("New password must be at least 6 characters");
3529
+ setIsLoading(false);
3530
+ return;
3531
+ }
3532
+ try {
3533
+ const response = await changePassword(oldPassword, newPassword);
3534
+ if (response.success) {
3535
+ setSuccess(true);
3536
+ setOldPassword("");
3537
+ setNewPassword("");
3538
+ setConfirmPassword("");
3539
+ onSuccess?.();
3540
+ } else {
3541
+ setError(response.message || "Failed to change password");
3542
+ }
3543
+ } catch (err) {
3544
+ setError(err instanceof Error ? err.message : "An error occurred");
3545
+ } finally {
3546
+ setIsLoading(false);
3547
+ }
3548
+ };
3549
+ return /* @__PURE__ */ jsx("div", { style: {
3550
+ maxWidth: "400px",
3551
+ margin: "0 auto",
3552
+ padding: "30px",
3553
+ borderRadius: "12px",
3554
+ boxShadow: "0 4px 20px rgba(0, 0, 0, 0.1)",
3555
+ backgroundColor: "#ffffff",
3556
+ border: "1px solid #eaeaea",
3557
+ ...appearance?.elements?.card
3558
+ }, children: /* @__PURE__ */ jsxs("form", { onSubmit: handleSubmit, children: [
3559
+ /* @__PURE__ */ jsx("h2", { style: {
3560
+ textAlign: "center",
3561
+ marginBottom: "24px",
3562
+ color: "#1f2937",
3563
+ fontSize: "24px",
3564
+ fontWeight: 600,
3565
+ ...appearance?.elements?.headerTitle
3566
+ }, children: "Change Password" }),
3567
+ error && /* @__PURE__ */ jsx("div", { style: {
3568
+ padding: "12px 16px",
3569
+ marginBottom: "20px",
3570
+ backgroundColor: "#fee",
3571
+ color: "#c33",
3572
+ border: "1px solid #fcc",
3573
+ borderRadius: "8px",
3574
+ fontSize: "14px"
3575
+ }, children: error }),
3576
+ success && /* @__PURE__ */ jsx("div", { style: {
3577
+ padding: "12px 16px",
3578
+ marginBottom: "20px",
3579
+ backgroundColor: "#efe",
3580
+ color: "#3c3",
3581
+ border: "1px solid #cfc",
3582
+ borderRadius: "8px",
3583
+ fontSize: "14px"
3584
+ }, children: "Password changed successfully!" }),
3585
+ /* @__PURE__ */ jsxs("div", { style: { marginBottom: "20px" }, children: [
3586
+ /* @__PURE__ */ jsx("label", { htmlFor: "oldPassword", style: {
3587
+ display: "block",
3588
+ marginBottom: "8px",
3589
+ fontWeight: 500,
3590
+ color: "#374151",
3591
+ fontSize: "14px"
3592
+ }, children: "Current password" }),
3593
+ /* @__PURE__ */ jsx(
3594
+ "input",
3595
+ {
3596
+ id: "oldPassword",
3597
+ type: showPasswords ? "text" : "password",
3598
+ value: oldPassword,
3599
+ onChange: (e) => setOldPassword(e.target.value),
3600
+ required: true,
3601
+ disabled: isLoading,
3602
+ style: {
3603
+ width: "100%",
3604
+ padding: "12px 16px",
3605
+ border: "1px solid #ddd",
3606
+ borderRadius: "8px",
3607
+ fontSize: "16px",
3608
+ boxSizing: "border-box",
3609
+ ...appearance?.elements?.formFieldInput
3610
+ },
3611
+ placeholder: "Enter current password"
3612
+ }
3613
+ )
3614
+ ] }),
3615
+ /* @__PURE__ */ jsxs("div", { style: { marginBottom: "20px" }, children: [
3616
+ /* @__PURE__ */ jsx("label", { htmlFor: "newPassword", style: {
3617
+ display: "block",
3618
+ marginBottom: "8px",
3619
+ fontWeight: 500,
3620
+ color: "#374151",
3621
+ fontSize: "14px"
3622
+ }, children: "New password" }),
3623
+ /* @__PURE__ */ jsx(
3624
+ "input",
3625
+ {
3626
+ id: "newPassword",
3627
+ type: showPasswords ? "text" : "password",
3628
+ value: newPassword,
3629
+ onChange: (e) => setNewPassword(e.target.value),
3630
+ required: true,
3631
+ disabled: isLoading,
3632
+ minLength: 6,
3633
+ style: {
3634
+ width: "100%",
3635
+ padding: "12px 16px",
3636
+ border: "1px solid #ddd",
3637
+ borderRadius: "8px",
3638
+ fontSize: "16px",
3639
+ boxSizing: "border-box",
3640
+ ...appearance?.elements?.formFieldInput
3641
+ },
3642
+ placeholder: "Enter new password"
3643
+ }
3644
+ ),
3645
+ newPassword && /* @__PURE__ */ jsxs("div", { style: { marginTop: "8px" }, children: [
3646
+ /* @__PURE__ */ jsx("div", { style: {
3647
+ height: "4px",
3648
+ backgroundColor: "#eee",
3649
+ borderRadius: "2px",
3650
+ overflow: "hidden"
3651
+ }, children: /* @__PURE__ */ jsx("div", { style: {
3652
+ height: "100%",
3653
+ width: passwordStrength.strength === "weak" ? "33%" : passwordStrength.strength === "medium" ? "66%" : "100%",
3654
+ backgroundColor: passwordStrength.color,
3655
+ transition: "all 0.3s ease"
3656
+ } }) }),
3657
+ /* @__PURE__ */ jsxs("p", { style: {
3658
+ fontSize: "12px",
3659
+ color: passwordStrength.color,
3660
+ marginTop: "4px",
3661
+ textTransform: "capitalize"
3662
+ }, children: [
3663
+ passwordStrength.strength,
3664
+ " password"
3665
+ ] })
3666
+ ] })
3667
+ ] }),
3668
+ /* @__PURE__ */ jsxs("div", { style: { marginBottom: "20px" }, children: [
3669
+ /* @__PURE__ */ jsx("label", { htmlFor: "confirmPassword", style: {
3670
+ display: "block",
3671
+ marginBottom: "8px",
3672
+ fontWeight: 500,
3673
+ color: "#374151",
3674
+ fontSize: "14px"
3675
+ }, children: "Confirm new password" }),
3676
+ /* @__PURE__ */ jsx(
3677
+ "input",
3678
+ {
3679
+ id: "confirmPassword",
3680
+ type: showPasswords ? "text" : "password",
3681
+ value: confirmPassword,
3682
+ onChange: (e) => setConfirmPassword(e.target.value),
3683
+ required: true,
3684
+ disabled: isLoading,
3685
+ style: {
3686
+ width: "100%",
3687
+ padding: "12px 16px",
3688
+ border: "1px solid #ddd",
3689
+ borderRadius: "8px",
3690
+ fontSize: "16px",
3691
+ boxSizing: "border-box",
3692
+ ...appearance?.elements?.formFieldInput
3693
+ },
3694
+ placeholder: "Confirm new password"
3695
+ }
3696
+ )
3697
+ ] }),
3698
+ /* @__PURE__ */ jsx("div", { style: { marginBottom: "20px" }, children: /* @__PURE__ */ jsxs("label", { style: { display: "flex", alignItems: "center", cursor: "pointer" }, children: [
3699
+ /* @__PURE__ */ jsx(
3700
+ "input",
3701
+ {
3702
+ type: "checkbox",
3703
+ checked: showPasswords,
3704
+ onChange: (e) => setShowPasswords(e.target.checked),
3705
+ style: { marginRight: "8px" }
3706
+ }
3707
+ ),
3708
+ /* @__PURE__ */ jsx("span", { style: { fontSize: "14px", color: "#666" }, children: "Show passwords" })
3709
+ ] }) }),
3710
+ /* @__PURE__ */ jsx(
3711
+ "button",
3712
+ {
3713
+ type: "submit",
3714
+ disabled: isLoading,
3715
+ style: {
3716
+ width: "100%",
3717
+ padding: "14px",
3718
+ backgroundColor: "#007bff",
3719
+ color: "white",
3720
+ border: "none",
3721
+ borderRadius: "8px",
3722
+ fontSize: "16px",
3723
+ fontWeight: 600,
3724
+ cursor: "pointer",
3725
+ transition: "all 0.2s ease",
3726
+ ...appearance?.elements?.formButtonPrimary
3727
+ },
3728
+ children: isLoading ? "Changing password..." : "Change password"
3729
+ }
3730
+ )
3731
+ ] }) });
3732
+ };
3733
+ var UserProfile = ({
3734
+ showAvatar = true,
3735
+ showEmailChange = true,
3736
+ showPasswordChange = true
3737
+ }) => {
3738
+ const { user, updateProfile, updateAvatar, requestEmailChange } = useAuth();
3739
+ const [name, setName] = useState(user?.name || "");
3740
+ const [avatar, setAvatar] = useState("");
3741
+ const [newEmail, setNewEmail] = useState("");
3742
+ const [isLoading, setIsLoading] = useState(false);
3743
+ const [error, setError] = useState(null);
3744
+ const [success, setSuccess] = useState(null);
3745
+ const handleUpdateName = async (e) => {
3746
+ e.preventDefault();
3747
+ setIsLoading(true);
3748
+ setError(null);
3749
+ setSuccess(null);
3750
+ try {
3751
+ const response = await updateProfile({ name });
3752
+ if (response.success) {
3753
+ setSuccess("Name updated successfully!");
3754
+ } else {
3755
+ setError(response.message || "Failed to update name");
3756
+ }
3757
+ } catch (err) {
3758
+ setError(err instanceof Error ? err.message : "An error occurred");
3759
+ } finally {
3760
+ setIsLoading(false);
3761
+ }
3762
+ };
3763
+ const handleUpdateAvatar = async (e) => {
3764
+ e.preventDefault();
3765
+ setIsLoading(true);
3766
+ setError(null);
3767
+ setSuccess(null);
3768
+ try {
3769
+ const response = await updateAvatar(avatar);
3770
+ if (response.success) {
3771
+ setSuccess("Avatar updated successfully!");
3772
+ setAvatar("");
3773
+ } else {
3774
+ setError(response.message || "Failed to update avatar");
3775
+ }
3776
+ } catch (err) {
3777
+ setError(err instanceof Error ? err.message : "An error occurred");
3778
+ } finally {
3779
+ setIsLoading(false);
3780
+ }
3781
+ };
3782
+ const handleRequestEmailChange = async (e) => {
3783
+ e.preventDefault();
3784
+ setIsLoading(true);
3785
+ setError(null);
3786
+ setSuccess(null);
3787
+ try {
3788
+ const response = await requestEmailChange(newEmail);
3789
+ if (response.success) {
3790
+ setSuccess("Verification email sent! Please check your inbox.");
3791
+ setNewEmail("");
3792
+ } else {
3793
+ setError(response.message || "Failed to request email change");
3794
+ }
3795
+ } catch (err) {
3796
+ setError(err instanceof Error ? err.message : "An error occurred");
3797
+ } finally {
3798
+ setIsLoading(false);
3799
+ }
3800
+ };
3801
+ if (!user)
3802
+ return null;
3803
+ return /* @__PURE__ */ jsxs("div", { style: { maxWidth: "600px", margin: "0 auto", padding: "20px" }, children: [
3804
+ /* @__PURE__ */ jsx("h2", { style: { marginBottom: "24px", fontSize: "24px", fontWeight: 600 }, children: "Profile Settings" }),
3805
+ error && /* @__PURE__ */ jsx("div", { style: {
3806
+ padding: "12px 16px",
3807
+ marginBottom: "20px",
3808
+ backgroundColor: "#fee",
3809
+ color: "#c33",
3810
+ border: "1px solid #fcc",
3811
+ borderRadius: "8px",
3812
+ fontSize: "14px"
3813
+ }, children: error }),
3814
+ success && /* @__PURE__ */ jsx("div", { style: {
3815
+ padding: "12px 16px",
3816
+ marginBottom: "20px",
3817
+ backgroundColor: "#efe",
3818
+ color: "#3c3",
3819
+ border: "1px solid #cfc",
3820
+ borderRadius: "8px",
3821
+ fontSize: "14px"
3822
+ }, children: success }),
3823
+ /* @__PURE__ */ jsxs("div", { style: {
3824
+ padding: "20px",
3825
+ backgroundColor: "#fff",
3826
+ borderRadius: "8px",
3827
+ boxShadow: "0 2px 8px rgba(0,0,0,0.1)",
3828
+ marginBottom: "20px"
3829
+ }, children: [
3830
+ /* @__PURE__ */ jsx("h3", { style: { marginBottom: "16px", fontSize: "18px", fontWeight: 600 }, children: "Update Name" }),
3831
+ /* @__PURE__ */ jsxs("form", { onSubmit: handleUpdateName, children: [
3832
+ /* @__PURE__ */ jsx(
3833
+ "input",
3834
+ {
3835
+ type: "text",
3836
+ value: name,
3837
+ onChange: (e) => setName(e.target.value),
3838
+ required: true,
3839
+ disabled: isLoading,
3840
+ style: {
3841
+ width: "100%",
3842
+ padding: "12px 16px",
3843
+ border: "1px solid #ddd",
3844
+ borderRadius: "8px",
3845
+ fontSize: "16px",
3846
+ boxSizing: "border-box",
3847
+ marginBottom: "12px"
3848
+ },
3849
+ placeholder: "Your name"
3850
+ }
3851
+ ),
3852
+ /* @__PURE__ */ jsx(
3853
+ "button",
3854
+ {
3855
+ type: "submit",
3856
+ disabled: isLoading,
3857
+ style: {
3858
+ padding: "10px 20px",
3859
+ backgroundColor: "#007bff",
3860
+ color: "white",
3861
+ border: "none",
3862
+ borderRadius: "8px",
3863
+ fontSize: "14px",
3864
+ fontWeight: 600,
3865
+ cursor: "pointer"
3866
+ },
3867
+ children: "Update Name"
3868
+ }
3869
+ )
3870
+ ] })
3871
+ ] }),
3872
+ showAvatar && /* @__PURE__ */ jsxs("div", { style: {
3873
+ padding: "20px",
3874
+ backgroundColor: "#fff",
3875
+ borderRadius: "8px",
3876
+ boxShadow: "0 2px 8px rgba(0,0,0,0.1)",
3877
+ marginBottom: "20px"
3878
+ }, children: [
3879
+ /* @__PURE__ */ jsx("h3", { style: { marginBottom: "16px", fontSize: "18px", fontWeight: 600 }, children: "Update Avatar" }),
3880
+ /* @__PURE__ */ jsxs("form", { onSubmit: handleUpdateAvatar, children: [
3881
+ /* @__PURE__ */ jsx(
3882
+ "input",
3883
+ {
3884
+ type: "url",
3885
+ value: avatar,
3886
+ onChange: (e) => setAvatar(e.target.value),
3887
+ required: true,
3888
+ disabled: isLoading,
3889
+ style: {
3890
+ width: "100%",
3891
+ padding: "12px 16px",
3892
+ border: "1px solid #ddd",
3893
+ borderRadius: "8px",
3894
+ fontSize: "16px",
3895
+ boxSizing: "border-box",
3896
+ marginBottom: "12px"
3897
+ },
3898
+ placeholder: "Avatar URL"
3899
+ }
3900
+ ),
3901
+ /* @__PURE__ */ jsx(
3902
+ "button",
3903
+ {
3904
+ type: "submit",
3905
+ disabled: isLoading,
3906
+ style: {
3907
+ padding: "10px 20px",
3908
+ backgroundColor: "#007bff",
3909
+ color: "white",
3910
+ border: "none",
3911
+ borderRadius: "8px",
3912
+ fontSize: "14px",
3913
+ fontWeight: 600,
3914
+ cursor: "pointer"
3915
+ },
3916
+ children: "Update Avatar"
3917
+ }
3918
+ )
3919
+ ] })
3920
+ ] }),
3921
+ showEmailChange && /* @__PURE__ */ jsxs("div", { style: {
3922
+ padding: "20px",
3923
+ backgroundColor: "#fff",
3924
+ borderRadius: "8px",
3925
+ boxShadow: "0 2px 8px rgba(0,0,0,0.1)",
3926
+ marginBottom: "20px"
3927
+ }, children: [
3928
+ /* @__PURE__ */ jsx("h3", { style: { marginBottom: "16px", fontSize: "18px", fontWeight: 600 }, children: "Change Email" }),
3929
+ /* @__PURE__ */ jsxs("p", { style: { fontSize: "14px", color: "#666", marginBottom: "12px" }, children: [
3930
+ "Current email: ",
3931
+ /* @__PURE__ */ jsx("strong", { children: user.email })
3932
+ ] }),
3933
+ /* @__PURE__ */ jsxs("form", { onSubmit: handleRequestEmailChange, children: [
3934
+ /* @__PURE__ */ jsx(
3935
+ "input",
3936
+ {
3937
+ type: "email",
3938
+ value: newEmail,
3939
+ onChange: (e) => setNewEmail(e.target.value),
3940
+ required: true,
3941
+ disabled: isLoading,
3942
+ style: {
3943
+ width: "100%",
3944
+ padding: "12px 16px",
3945
+ border: "1px solid #ddd",
3946
+ borderRadius: "8px",
3947
+ fontSize: "16px",
3948
+ boxSizing: "border-box",
3949
+ marginBottom: "12px"
3950
+ },
3951
+ placeholder: "New email address"
3952
+ }
3953
+ ),
3954
+ /* @__PURE__ */ jsx(
3955
+ "button",
3956
+ {
3957
+ type: "submit",
3958
+ disabled: isLoading,
3959
+ style: {
3960
+ padding: "10px 20px",
3961
+ backgroundColor: "#007bff",
3962
+ color: "white",
3963
+ border: "none",
3964
+ borderRadius: "8px",
3965
+ fontSize: "14px",
3966
+ fontWeight: 600,
3967
+ cursor: "pointer"
3968
+ },
3969
+ children: "Request Email Change"
3970
+ }
3971
+ )
3972
+ ] })
3973
+ ] })
3974
+ ] });
3975
+ };
3976
+
3977
+ // src/react/index.ts
3978
+ var react_exports = {};
3979
+ __export(react_exports, {
3980
+ AuthFlow: () => AuthFlow,
3981
+ AuthProvider: () => AuthProvider,
3982
+ ChangePassword: () => ChangePassword,
3983
+ EmailVerificationPage: () => EmailVerificationPage,
3984
+ ForgotPassword: () => ForgotPassword,
3985
+ LoginForm: () => LoginForm,
3986
+ OtpForm: () => OtpForm,
3987
+ ProtectedRoute: () => ProtectedRoute,
3988
+ PublicRoute: () => PublicRoute,
3989
+ RegisterForm: () => RegisterForm,
3990
+ ResetPassword: () => ResetPassword,
3991
+ SignIn: () => SignIn,
3992
+ SignOut: () => SignOut,
3993
+ SignUp: () => SignUp,
3994
+ UserButton: () => UserButton,
3995
+ UserProfile: () => UserProfile,
3996
+ VerifyEmail: () => VerifyEmail,
3997
+ useAuth: () => useAuth,
3998
+ useAuthLegacy: () => useAuth2
3999
+ });
1757
4000
 
1758
4001
  // src/node/index.ts
1759
4002
  var node_exports = {};
@@ -1769,11 +4012,11 @@ var AuthClient = class extends AuthService {
1769
4012
  // Override methods that require browser-specific features
1770
4013
  // For Node.js, token persistence must be handled manually
1771
4014
  async register(data) {
1772
- const registerData = { ...data };
1773
- if (!registerData.frontendBaseUrl) {
1774
- registerData.frontendBaseUrl = process.env.FRONTEND_BASE_URL || process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL;
4015
+ const frontendBaseUrl = process.env.FRONTEND_BASE_URL || process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL;
4016
+ if (frontendBaseUrl) {
4017
+ this["httpClient"].setFrontendBaseUrl(frontendBaseUrl);
1775
4018
  }
1776
- const response = await this["httpClient"].post("/api/v1/auth/register", registerData);
4019
+ const response = await this["httpClient"].post("/api/v1/auth/register", data);
1777
4020
  if (response.success && response.message === "Registration data saved. Verification email sent. Please check your inbox.") {
1778
4021
  return response;
1779
4022
  }
@@ -1839,6 +4082,6 @@ var AuthClient = class extends AuthService {
1839
4082
  }
1840
4083
  };
1841
4084
 
1842
- export { AuthService, HttpClient, node_exports as node, react_exports as react };
4085
+ export { AuthFlow, AuthProvider, AuthService, ChangePassword, EmailVerificationPage, ForgotPassword, HttpClient, LoginForm, OtpForm, ProtectedRoute, PublicRoute, RegisterForm, ResetPassword, SignIn, SignOut, SignUp, UserButton, UserProfile, VerifyEmail, node_exports as node, react_exports as react, useAuth };
1843
4086
  //# sourceMappingURL=out.js.map
1844
4087
  //# sourceMappingURL=index.mjs.map