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