@thetechfossil/auth2 1.2.14 → 1.2.16

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.
@@ -3,20 +3,19 @@
3
3
 
4
4
  var axios = require('axios');
5
5
  var upfiles = require('@thetechfossil/upfiles');
6
- var React3 = require('react');
6
+ var React = require('react');
7
7
  var jsxRuntime = require('react/jsx-runtime');
8
8
 
9
9
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
10
 
11
11
  var axios__default = /*#__PURE__*/_interopDefault(axios);
12
- var React3__default = /*#__PURE__*/_interopDefault(React3);
12
+ var React__default = /*#__PURE__*/_interopDefault(React);
13
13
 
14
14
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
15
15
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
16
16
  }) : x)(function(x) {
17
- if (typeof require !== "undefined")
18
- return require.apply(this, arguments);
19
- throw new Error('Dynamic require of "' + x + '" is not supported');
17
+ if (typeof require !== "undefined") return require.apply(this, arguments);
18
+ throw Error('Dynamic require of "' + x + '" is not supported');
20
19
  });
21
20
  var HttpClient = class {
22
21
  constructor(baseUrl, defaultHeaders = {}) {
@@ -70,6 +69,11 @@ var HttpClient = class {
70
69
  return Promise.reject(refreshError);
71
70
  }
72
71
  }
72
+ if (error.response && error.response.data && error.response.data.message) {
73
+ const customError = new Error(error.response.data.message);
74
+ customError.response = error.response;
75
+ return Promise.reject(customError);
76
+ }
73
77
  return Promise.reject(error);
74
78
  }
75
79
  );
@@ -189,8 +193,7 @@ var AuthService = class {
189
193
  return this.token;
190
194
  }
191
195
  getCurrentUser() {
192
- if (!this.token)
193
- return null;
196
+ if (!this.token) return null;
194
197
  try {
195
198
  const payload = JSON.parse(atob(this.token.split(".")[1]));
196
199
  return payload.user || null;
@@ -201,8 +204,7 @@ var AuthService = class {
201
204
  }
202
205
  // CSRF Token Management
203
206
  async refreshCsrfToken() {
204
- if (!this.config.csrfEnabled)
205
- return;
207
+ if (!this.config.csrfEnabled) return;
206
208
  try {
207
209
  const response = await this.httpClient.get("/api/v1/auth/csrf-token");
208
210
  if (response.csrfToken) {
@@ -509,11 +511,11 @@ var AuthService = class {
509
511
  }
510
512
  };
511
513
  var useAuth = (config) => {
512
- const [authService] = React3.useState(() => new AuthService(config));
513
- const [user, setUser] = React3.useState(null);
514
- const [isAuthenticated, setIsAuthenticated] = React3.useState(false);
515
- const [loading, setLoading] = React3.useState(true);
516
- const checkAuthStatus = React3.useCallback(() => {
514
+ const [authService] = React.useState(() => new AuthService(config));
515
+ const [user, setUser] = React.useState(null);
516
+ const [isAuthenticated, setIsAuthenticated] = React.useState(false);
517
+ const [loading, setLoading] = React.useState(true);
518
+ const checkAuthStatus = React.useCallback(() => {
517
519
  const authenticated = authService.isAuthenticated();
518
520
  setIsAuthenticated(authenticated);
519
521
  if (authenticated) {
@@ -524,10 +526,10 @@ var useAuth = (config) => {
524
526
  }
525
527
  setLoading(false);
526
528
  }, [authService]);
527
- React3.useEffect(() => {
529
+ React.useEffect(() => {
528
530
  checkAuthStatus();
529
531
  }, [checkAuthStatus]);
530
- const register = React3.useCallback(async (data) => {
532
+ const register = React.useCallback(async (data) => {
531
533
  setLoading(true);
532
534
  try {
533
535
  const response = await authService.register(data);
@@ -536,7 +538,7 @@ var useAuth = (config) => {
536
538
  setLoading(false);
537
539
  }
538
540
  }, [authService]);
539
- const login = React3.useCallback(async (data) => {
541
+ const login = React.useCallback(async (data) => {
540
542
  setLoading(true);
541
543
  try {
542
544
  const response = await authService.login(data);
@@ -549,7 +551,7 @@ var useAuth = (config) => {
549
551
  setLoading(false);
550
552
  }
551
553
  }, [authService]);
552
- const verify = React3.useCallback(async (data) => {
554
+ const verify = React.useCallback(async (data) => {
553
555
  setLoading(true);
554
556
  try {
555
557
  const response = await authService.verify(data);
@@ -562,7 +564,7 @@ var useAuth = (config) => {
562
564
  setLoading(false);
563
565
  }
564
566
  }, [authService]);
565
- const verifyEmailToken = React3.useCallback(async (token) => {
567
+ const verifyEmailToken = React.useCallback(async (token) => {
566
568
  setLoading(true);
567
569
  try {
568
570
  const response = await authService.verifyEmailToken(token);
@@ -575,7 +577,7 @@ var useAuth = (config) => {
575
577
  setLoading(false);
576
578
  }
577
579
  }, [authService]);
578
- const logout = React3.useCallback(async () => {
580
+ const logout = React.useCallback(async () => {
579
581
  setLoading(true);
580
582
  try {
581
583
  await authService.logout();
@@ -585,7 +587,7 @@ var useAuth = (config) => {
585
587
  setLoading(false);
586
588
  }
587
589
  }, [authService]);
588
- const updateProfile = React3.useCallback(async (data) => {
590
+ const updateProfile = React.useCallback(async (data) => {
589
591
  setLoading(true);
590
592
  try {
591
593
  const response = await authService.updateProfile(data);
@@ -597,7 +599,7 @@ var useAuth = (config) => {
597
599
  setLoading(false);
598
600
  }
599
601
  }, [authService]);
600
- const getProfile = React3.useCallback(async () => {
602
+ const getProfile = React.useCallback(async () => {
601
603
  setLoading(true);
602
604
  try {
603
605
  const userData = await authService.getProfile();
@@ -607,7 +609,7 @@ var useAuth = (config) => {
607
609
  setLoading(false);
608
610
  }
609
611
  }, [authService]);
610
- const getAllUsers = React3.useCallback(async () => {
612
+ const getAllUsers = React.useCallback(async () => {
611
613
  setLoading(true);
612
614
  try {
613
615
  return await authService.getAllUsers();
@@ -615,7 +617,7 @@ var useAuth = (config) => {
615
617
  setLoading(false);
616
618
  }
617
619
  }, [authService]);
618
- const getUserById = React3.useCallback(async (id) => {
620
+ const getUserById = React.useCallback(async (id) => {
619
621
  setLoading(true);
620
622
  try {
621
623
  return await authService.getUserById(id);
@@ -623,7 +625,7 @@ var useAuth = (config) => {
623
625
  setLoading(false);
624
626
  }
625
627
  }, [authService]);
626
- const uploadAndUpdateAvatar = React3.useCallback(async (file) => {
628
+ const uploadAndUpdateAvatar = React.useCallback(async (file) => {
627
629
  setLoading(true);
628
630
  try {
629
631
  const response = await authService.uploadAndUpdateAvatar(file);
@@ -651,11 +653,11 @@ var useAuth = (config) => {
651
653
  uploadAndUpdateAvatar
652
654
  };
653
655
  };
654
- var ThemeContext = React3.createContext({ theme: "light", mounted: false });
656
+ var ThemeContext = React__default.default.createContext({ theme: "light", mounted: false });
655
657
  function AuthThemeProvider({ children }) {
656
- const [theme, setTheme] = React3.useState("light");
657
- const [mounted, setMounted] = React3.useState(false);
658
- React3.useEffect(() => {
658
+ const [theme, setTheme] = React.useState("light");
659
+ const [mounted, setMounted] = React.useState(false);
660
+ React.useEffect(() => {
659
661
  const detectTheme = () => {
660
662
  const htmlElement = document.documentElement;
661
663
  const bodyElement = document.body;
@@ -700,9 +702,9 @@ function AuthThemeProvider({ children }) {
700
702
  return /* @__PURE__ */ jsxRuntime.jsx(ThemeContext.Provider, { value: { theme, mounted }, children });
701
703
  }
702
704
  function useAuthTheme() {
703
- return React3.useContext(ThemeContext);
705
+ return React.useContext(ThemeContext);
704
706
  }
705
- var AuthContext = React3.createContext(void 0);
707
+ var AuthContext = React.createContext(void 0);
706
708
  var AuthProvider = ({ children, config }) => {
707
709
  const authConfig = {
708
710
  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"),
@@ -710,29 +712,35 @@ var AuthProvider = ({ children, config }) => {
710
712
  csrfEnabled: config?.csrfEnabled !== void 0 ? config.csrfEnabled : true,
711
713
  upfilesConfig: config?.upfilesConfig
712
714
  };
713
- const [authService] = React3.useState(() => new AuthService(authConfig));
714
- const [user, setUser] = React3.useState(null);
715
- const [isLoaded, setIsLoaded] = React3.useState(false);
716
- const [loading, setLoading] = React3.useState(false);
717
- const checkAuthStatus = React3.useCallback(async () => {
715
+ const [authService] = React.useState(() => new AuthService(authConfig));
716
+ const [user, setUser] = React.useState(null);
717
+ const [isLoaded, setIsLoaded] = React.useState(false);
718
+ const [loading, setLoading] = React.useState(false);
719
+ const checkAuthStatus = React.useCallback(async () => {
718
720
  const authenticated = authService.isAuthenticated();
719
721
  if (authenticated) {
720
722
  try {
721
- const currentUser = authService.getCurrentUser();
722
- setUser(currentUser);
723
+ const freshUser = await authService.getProfile();
724
+ setUser(freshUser);
723
725
  } catch (error) {
724
- console.error("Failed to get current user:", error);
725
- setUser(null);
726
+ console.error("Failed to fetch fresh user profile, falling back to token:", error);
727
+ try {
728
+ const currentUser = authService.getCurrentUser();
729
+ setUser(currentUser);
730
+ } catch (fallbackError) {
731
+ console.error("Failed to get current user from token:", fallbackError);
732
+ setUser(null);
733
+ }
726
734
  }
727
735
  } else {
728
736
  setUser(null);
729
737
  }
730
738
  setIsLoaded(true);
731
739
  }, [authService]);
732
- React3.useEffect(() => {
740
+ React.useEffect(() => {
733
741
  checkAuthStatus();
734
742
  }, [checkAuthStatus]);
735
- const signIn = React3.useCallback(async (data) => {
743
+ const signIn = React.useCallback(async (data) => {
736
744
  setLoading(true);
737
745
  try {
738
746
  const response = await authService.login(data);
@@ -744,7 +752,7 @@ var AuthProvider = ({ children, config }) => {
744
752
  setLoading(false);
745
753
  }
746
754
  }, [authService]);
747
- const signUp = React3.useCallback(async (data) => {
755
+ const signUp = React.useCallback(async (data) => {
748
756
  setLoading(true);
749
757
  try {
750
758
  const response = await authService.register(data);
@@ -753,7 +761,7 @@ var AuthProvider = ({ children, config }) => {
753
761
  setLoading(false);
754
762
  }
755
763
  }, [authService]);
756
- const signOut = React3.useCallback(async () => {
764
+ const signOut = React.useCallback(async () => {
757
765
  setLoading(true);
758
766
  try {
759
767
  await authService.logout();
@@ -762,7 +770,7 @@ var AuthProvider = ({ children, config }) => {
762
770
  setLoading(false);
763
771
  }
764
772
  }, [authService]);
765
- const verify = React3.useCallback(async (data) => {
773
+ const verify = React.useCallback(async (data) => {
766
774
  setLoading(true);
767
775
  try {
768
776
  const response = await authService.verify(data);
@@ -774,7 +782,7 @@ var AuthProvider = ({ children, config }) => {
774
782
  setLoading(false);
775
783
  }
776
784
  }, [authService]);
777
- const verifyEmailToken = React3.useCallback(async (token) => {
785
+ const verifyEmailToken = React.useCallback(async (token) => {
778
786
  setLoading(true);
779
787
  try {
780
788
  const response = await authService.verifyEmailToken(token);
@@ -786,7 +794,7 @@ var AuthProvider = ({ children, config }) => {
786
794
  setLoading(false);
787
795
  }
788
796
  }, [authService]);
789
- const updateProfile = React3.useCallback(async (data) => {
797
+ const updateProfile = React.useCallback(async (data) => {
790
798
  setLoading(true);
791
799
  try {
792
800
  const response = await authService.updateProfile(data);
@@ -798,7 +806,7 @@ var AuthProvider = ({ children, config }) => {
798
806
  setLoading(false);
799
807
  }
800
808
  }, [authService]);
801
- const getProfile = React3.useCallback(async () => {
809
+ const getProfile = React.useCallback(async () => {
802
810
  setLoading(true);
803
811
  try {
804
812
  const userData = await authService.getProfile();
@@ -808,13 +816,13 @@ var AuthProvider = ({ children, config }) => {
808
816
  setLoading(false);
809
817
  }
810
818
  }, [authService]);
811
- const signInWithOAuth = React3.useCallback((provider) => {
819
+ const signInWithOAuth = React.useCallback((provider) => {
812
820
  authService.loginWithOAuth(provider);
813
821
  }, [authService]);
814
- const linkOAuthProvider = React3.useCallback((provider) => {
822
+ const linkOAuthProvider = React.useCallback((provider) => {
815
823
  authService.linkOAuthProvider(provider);
816
824
  }, [authService]);
817
- const unlinkOAuthProvider = React3.useCallback(async (provider) => {
825
+ const unlinkOAuthProvider = React.useCallback(async (provider) => {
818
826
  setLoading(true);
819
827
  try {
820
828
  return await authService.unlinkOAuthProvider(provider);
@@ -822,7 +830,7 @@ var AuthProvider = ({ children, config }) => {
822
830
  setLoading(false);
823
831
  }
824
832
  }, [authService]);
825
- const forgotPassword = React3.useCallback(async (email) => {
833
+ const forgotPassword = React.useCallback(async (email) => {
826
834
  setLoading(true);
827
835
  try {
828
836
  return await authService.forgotPassword(email);
@@ -830,7 +838,7 @@ var AuthProvider = ({ children, config }) => {
830
838
  setLoading(false);
831
839
  }
832
840
  }, [authService]);
833
- const resetPassword = React3.useCallback(async (token, password) => {
841
+ const resetPassword = React.useCallback(async (token, password) => {
834
842
  setLoading(true);
835
843
  try {
836
844
  return await authService.resetPassword(token, password);
@@ -838,7 +846,7 @@ var AuthProvider = ({ children, config }) => {
838
846
  setLoading(false);
839
847
  }
840
848
  }, [authService]);
841
- const changePassword = React3.useCallback(async (oldPassword, newPassword) => {
849
+ const changePassword = React.useCallback(async (oldPassword, newPassword) => {
842
850
  setLoading(true);
843
851
  try {
844
852
  return await authService.changePassword(oldPassword, newPassword);
@@ -846,7 +854,7 @@ var AuthProvider = ({ children, config }) => {
846
854
  setLoading(false);
847
855
  }
848
856
  }, [authService]);
849
- const updateAvatar = React3.useCallback(async (avatar) => {
857
+ const updateAvatar = React.useCallback(async (avatar) => {
850
858
  setLoading(true);
851
859
  try {
852
860
  const response = await authService.updateAvatar(avatar);
@@ -858,7 +866,7 @@ var AuthProvider = ({ children, config }) => {
858
866
  setLoading(false);
859
867
  }
860
868
  }, [authService]);
861
- const uploadAndUpdateAvatar = React3.useCallback(async (file) => {
869
+ const uploadAndUpdateAvatar = React.useCallback(async (file) => {
862
870
  setLoading(true);
863
871
  try {
864
872
  const response = await authService.uploadAndUpdateAvatar(file);
@@ -870,7 +878,7 @@ var AuthProvider = ({ children, config }) => {
870
878
  setLoading(false);
871
879
  }
872
880
  }, [authService]);
873
- const requestEmailChange = React3.useCallback(async (newEmail) => {
881
+ const requestEmailChange = React.useCallback(async (newEmail) => {
874
882
  setLoading(true);
875
883
  try {
876
884
  return await authService.requestEmailChange(newEmail);
@@ -878,7 +886,7 @@ var AuthProvider = ({ children, config }) => {
878
886
  setLoading(false);
879
887
  }
880
888
  }, [authService]);
881
- const verifyEmailChange = React3.useCallback(async (token) => {
889
+ const verifyEmailChange = React.useCallback(async (token) => {
882
890
  setLoading(true);
883
891
  try {
884
892
  const response = await authService.verifyEmailChange(token);
@@ -890,7 +898,7 @@ var AuthProvider = ({ children, config }) => {
890
898
  setLoading(false);
891
899
  }
892
900
  }, [authService]);
893
- const generate2FA = React3.useCallback(async () => {
901
+ const generate2FA = React.useCallback(async () => {
894
902
  setLoading(true);
895
903
  try {
896
904
  return await authService.generate2FA();
@@ -898,7 +906,7 @@ var AuthProvider = ({ children, config }) => {
898
906
  setLoading(false);
899
907
  }
900
908
  }, [authService]);
901
- const enable2FA = React3.useCallback(async (token) => {
909
+ const enable2FA = React.useCallback(async (token) => {
902
910
  setLoading(true);
903
911
  try {
904
912
  return await authService.enable2FA(token);
@@ -906,7 +914,7 @@ var AuthProvider = ({ children, config }) => {
906
914
  setLoading(false);
907
915
  }
908
916
  }, [authService]);
909
- const disable2FA = React3.useCallback(async (token) => {
917
+ const disable2FA = React.useCallback(async (token) => {
910
918
  setLoading(true);
911
919
  try {
912
920
  return await authService.disable2FA(token);
@@ -914,7 +922,7 @@ var AuthProvider = ({ children, config }) => {
914
922
  setLoading(false);
915
923
  }
916
924
  }, [authService]);
917
- const validate2FA = React3.useCallback(async (token) => {
925
+ const validate2FA = React.useCallback(async (token) => {
918
926
  setLoading(true);
919
927
  try {
920
928
  return await authService.validate2FA(token);
@@ -922,7 +930,7 @@ var AuthProvider = ({ children, config }) => {
922
930
  setLoading(false);
923
931
  }
924
932
  }, [authService]);
925
- const getSessions = React3.useCallback(async () => {
933
+ const getSessions = React.useCallback(async () => {
926
934
  setLoading(true);
927
935
  try {
928
936
  return await authService.getSessions();
@@ -930,7 +938,7 @@ var AuthProvider = ({ children, config }) => {
930
938
  setLoading(false);
931
939
  }
932
940
  }, [authService]);
933
- const revokeSession = React3.useCallback(async (sessionId) => {
941
+ const revokeSession = React.useCallback(async (sessionId) => {
934
942
  setLoading(true);
935
943
  try {
936
944
  return await authService.revokeSession(sessionId);
@@ -938,7 +946,7 @@ var AuthProvider = ({ children, config }) => {
938
946
  setLoading(false);
939
947
  }
940
948
  }, [authService]);
941
- const revokeAllSessions = React3.useCallback(async () => {
949
+ const revokeAllSessions = React.useCallback(async () => {
942
950
  setLoading(true);
943
951
  try {
944
952
  const response = await authService.revokeAllSessions();
@@ -982,7 +990,7 @@ var AuthProvider = ({ children, config }) => {
982
990
  return /* @__PURE__ */ jsxRuntime.jsx(AuthContext.Provider, { value, children: /* @__PURE__ */ jsxRuntime.jsx(AuthThemeProvider, { children }) });
983
991
  };
984
992
  var useAuth2 = () => {
985
- const context = React3.useContext(AuthContext);
993
+ const context = React.useContext(AuthContext);
986
994
  if (context === void 0) {
987
995
  throw new Error("useAuth must be used within an AuthProvider");
988
996
  }
@@ -1038,7 +1046,7 @@ try {
1038
1046
  } catch (error) {
1039
1047
  console.warn("react-phone-number-input not available, using fallback");
1040
1048
  }
1041
- var CustomPhoneInput = React3__default.default.forwardRef((props, ref) => /* @__PURE__ */ jsxRuntime.jsx(
1049
+ var CustomPhoneInput = React__default.default.forwardRef((props, ref) => /* @__PURE__ */ jsxRuntime.jsx(
1042
1050
  "input",
1043
1051
  {
1044
1052
  ...props,
@@ -1057,8 +1065,8 @@ var PhoneInput = ({
1057
1065
  style = {}
1058
1066
  }) => {
1059
1067
  const colors = useThemeColors();
1060
- const [defaultCountry, setDefaultCountry] = React3.useState("US");
1061
- const styleContent = React3.useMemo(() => `
1068
+ const [defaultCountry, setDefaultCountry] = React.useState("US");
1069
+ const styleContent = React.useMemo(() => `
1062
1070
  .PhoneInput {
1063
1071
  display: flex;
1064
1072
  align-items: center;
@@ -1170,7 +1178,7 @@ var PhoneInput = ({
1170
1178
  opacity: 0.6;
1171
1179
  }
1172
1180
  `, [colors]);
1173
- React3.useEffect(() => {
1181
+ React.useEffect(() => {
1174
1182
  const detectCountry = async () => {
1175
1183
  try {
1176
1184
  const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
@@ -1227,7 +1235,7 @@ var PhoneInput = ({
1227
1235
  };
1228
1236
  detectCountry();
1229
1237
  }, []);
1230
- const handleChange = React3.useMemo(() => (val) => {
1238
+ const handleChange = React.useMemo(() => (val) => {
1231
1239
  onChange(val || "");
1232
1240
  }, [onChange]);
1233
1241
  if (!PhoneInputWithCountry) {
@@ -1291,15 +1299,15 @@ var LoginForm = ({
1291
1299
  showOAuthButtons = true
1292
1300
  }) => {
1293
1301
  const colors = useThemeColors();
1294
- const [email, setEmail] = React3.useState("");
1295
- const [phoneNumber, setPhoneNumber] = React3.useState("");
1296
- const [usePhone, setUsePhone] = React3.useState(false);
1297
- const [password, setPassword] = React3.useState("");
1298
- const [usePassword, setUsePassword] = React3.useState(false);
1299
- const [showPassword, setShowPassword] = React3.useState(false);
1300
- const [isLoading, setIsLoading] = React3.useState(false);
1301
- const [error, setError] = React3.useState(null);
1302
- const [rememberMe, setRememberMe] = React3.useState(false);
1302
+ const [email, setEmail] = React.useState("");
1303
+ const [phoneNumber, setPhoneNumber] = React.useState("");
1304
+ const [usePhone, setUsePhone] = React.useState(false);
1305
+ const [password, setPassword] = React.useState("");
1306
+ const [usePassword, setUsePassword] = React.useState(false);
1307
+ const [showPassword, setShowPassword] = React.useState(false);
1308
+ const [isLoading, setIsLoading] = React.useState(false);
1309
+ const [error, setError] = React.useState(null);
1310
+ const [rememberMe, setRememberMe] = React.useState(false);
1303
1311
  const { login } = useAuth({
1304
1312
  baseUrl: config?.baseUrl || "http://localhost:7000"
1305
1313
  });
@@ -1753,33 +1761,25 @@ var RegisterForm = ({
1753
1761
  invitationToken
1754
1762
  }) => {
1755
1763
  const colors = useThemeColors();
1756
- const [name, setName] = React3.useState("");
1757
- const [email, setEmail] = React3.useState("");
1758
- const [phoneNumber, setPhoneNumber] = React3.useState("");
1759
- const [password, setPassword] = React3.useState("");
1760
- const [confirmPassword, setConfirmPassword] = React3.useState("");
1761
- const [isLoading, setIsLoading] = React3.useState(false);
1762
- const [error, setError] = React3.useState(null);
1763
- React3.useState(false);
1764
- React3.useState(false);
1764
+ const [name, setName] = React.useState("");
1765
+ const [email, setEmail] = React.useState("");
1766
+ const [phoneNumber, setPhoneNumber] = React.useState("");
1767
+ const [password, setPassword] = React.useState("");
1768
+ const [confirmPassword, setConfirmPassword] = React.useState("");
1769
+ const [isLoading, setIsLoading] = React.useState(false);
1770
+ const [error, setError] = React.useState(null);
1771
+ const [showPassword, setShowPassword] = React.useState(false);
1772
+ const [showConfirmPassword, setShowConfirmPassword] = React.useState(false);
1765
1773
  const getPasswordStrength = (pwd) => {
1766
- if (!pwd)
1767
- return { strength: "weak", score: 0, label: "" };
1774
+ if (!pwd) return { strength: "weak", score: 0, label: "" };
1768
1775
  let score = 0;
1769
- if (pwd.length >= 6)
1770
- score++;
1771
- if (pwd.length >= 8)
1772
- score++;
1773
- if (/[a-z]/.test(pwd) && /[A-Z]/.test(pwd))
1774
- score++;
1775
- if (/\d/.test(pwd))
1776
- score++;
1777
- if (/[^a-zA-Z\d]/.test(pwd))
1778
- score++;
1779
- if (score <= 2)
1780
- return { strength: "weak", score, label: "Weak" };
1781
- if (score <= 3)
1782
- return { strength: "medium", score, label: "Medium" };
1776
+ if (pwd.length >= 6) score++;
1777
+ if (pwd.length >= 8) score++;
1778
+ if (/[a-z]/.test(pwd) && /[A-Z]/.test(pwd)) score++;
1779
+ if (/\d/.test(pwd)) score++;
1780
+ if (/[^a-zA-Z\d]/.test(pwd)) score++;
1781
+ if (score <= 2) return { strength: "weak", score, label: "Weak" };
1782
+ if (score <= 3) return { strength: "medium", score, label: "Medium" };
1783
1783
  return { strength: "strong", score, label: "Strong" };
1784
1784
  };
1785
1785
  getPasswordStrength(password);
@@ -1831,10 +1831,8 @@ var RegisterForm = ({
1831
1831
  password,
1832
1832
  frontendBaseUrl: typeof window !== "undefined" ? process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || window.location.origin : void 0
1833
1833
  };
1834
- if (email)
1835
- registerData.email = email;
1836
- if (phoneNumber)
1837
- registerData.phoneNumber = phoneNumber;
1834
+ if (email) registerData.email = email;
1835
+ if (phoneNumber) registerData.phoneNumber = phoneNumber;
1838
1836
  const response = await register(registerData);
1839
1837
  if (response.success) {
1840
1838
  onRegisterSuccess?.();
@@ -2227,11 +2225,11 @@ var OtpForm = ({
2227
2225
  baseUrl
2228
2226
  }) => {
2229
2227
  const colors = useThemeColors();
2230
- const [otp, setOtp] = React3.useState("");
2231
- const [isLoading, setIsLoading] = React3.useState(false);
2232
- const [error, setError] = React3.useState(null);
2233
- const [resendCooldown, setResendCooldown] = React3.useState(0);
2234
- const [resendLoading, setResendLoading] = React3.useState(false);
2228
+ const [otp, setOtp] = React.useState("");
2229
+ const [isLoading, setIsLoading] = React.useState(false);
2230
+ const [error, setError] = React.useState(null);
2231
+ const [resendCooldown, setResendCooldown] = React.useState(0);
2232
+ const [resendLoading, setResendLoading] = React.useState(false);
2235
2233
  const { verify, login } = useAuth({
2236
2234
  baseUrl: baseUrl || process.env.NEXT_PUBLIC_AUTH_API_URL || "http://localhost:7000"
2237
2235
  });
@@ -2264,8 +2262,7 @@ var OtpForm = ({
2264
2262
  }
2265
2263
  };
2266
2264
  const handleResendOtp = async () => {
2267
- if (resendCooldown > 0 || resendLoading)
2268
- return;
2265
+ if (resendCooldown > 0 || resendLoading) return;
2269
2266
  setResendLoading(true);
2270
2267
  setError(null);
2271
2268
  try {
@@ -2443,9 +2440,9 @@ var AuthFlow = ({
2443
2440
  initialStep = "login",
2444
2441
  showTitle = true
2445
2442
  }) => {
2446
- const [step, setStep] = React3.useState(initialStep);
2447
- const [email, setEmail] = React3.useState("");
2448
- const [message, setMessage] = React3.useState(null);
2443
+ const [step, setStep] = React.useState(initialStep);
2444
+ const [email, setEmail] = React.useState("");
2445
+ const [message, setMessage] = React.useState(null);
2449
2446
  const handleLoginSuccess = (email2, needsOtpVerification) => {
2450
2447
  setEmail(email2);
2451
2448
  if (needsOtpVerification) {
@@ -2580,13 +2577,13 @@ var EmailVerificationPage = ({
2580
2577
  onVerificationError,
2581
2578
  baseUrl
2582
2579
  }) => {
2583
- const [isLoading, setIsLoading] = React3.useState(true);
2584
- const [message, setMessage] = React3.useState("");
2585
- const [isSuccess, setIsSuccess] = React3.useState(false);
2580
+ const [isLoading, setIsLoading] = React.useState(true);
2581
+ const [message, setMessage] = React.useState("");
2582
+ const [isSuccess, setIsSuccess] = React.useState(false);
2586
2583
  const { verifyEmailToken } = useAuth({
2587
2584
  baseUrl: baseUrl || (typeof window !== "undefined" ? window.location.origin : "http://localhost:7000")
2588
2585
  });
2589
- React3.useEffect(() => {
2586
+ React.useEffect(() => {
2590
2587
  const verifyEmail = async () => {
2591
2588
  if (!token) {
2592
2589
  setIsLoading(false);
@@ -2691,7 +2688,7 @@ var EmailVerificationPage = ({
2691
2688
  ] })
2692
2689
  ] }) });
2693
2690
  };
2694
- var ThemeWrapper = React3.forwardRef(
2691
+ var ThemeWrapper = React.forwardRef(
2695
2692
  ({ children, className = "", style }, ref) => {
2696
2693
  const { theme, mounted } = useAuthTheme();
2697
2694
  if (!mounted) {
@@ -2704,18 +2701,18 @@ ThemeWrapper.displayName = "ThemeWrapper";
2704
2701
  var SignIn = ({ redirectUrl, appearance }) => {
2705
2702
  const { signIn, isSignedIn, loading: authLoading } = useAuth2();
2706
2703
  const colors = useThemeColors();
2707
- const [email, setEmail] = React3.useState("");
2708
- const [phoneNumber, setPhoneNumber] = React3.useState("");
2709
- const [password, setPassword] = React3.useState("");
2710
- const [otp, setOtp] = React3.useState("");
2711
- const [usePassword, setUsePassword] = React3.useState(false);
2712
- const [usePhone, setUsePhone] = React3.useState(false);
2713
- const [showPassword, setShowPassword] = React3.useState(false);
2714
- const [isLoading, setIsLoading] = React3.useState(false);
2715
- const [error, setError] = React3.useState(null);
2716
- const [needsOtp, setNeedsOtp] = React3.useState(false);
2717
- const [success, setSuccess] = React3.useState(null);
2718
- React3.useEffect(() => {
2704
+ const [email, setEmail] = React.useState("");
2705
+ const [phoneNumber, setPhoneNumber] = React.useState("");
2706
+ const [password, setPassword] = React.useState("");
2707
+ const [otp, setOtp] = React.useState("");
2708
+ const [usePassword, setUsePassword] = React.useState(false);
2709
+ const [usePhone, setUsePhone] = React.useState(false);
2710
+ const [showPassword, setShowPassword] = React.useState(false);
2711
+ const [isLoading, setIsLoading] = React.useState(false);
2712
+ const [error, setError] = React.useState(null);
2713
+ const [needsOtp, setNeedsOtp] = React.useState(false);
2714
+ const [success, setSuccess] = React.useState(null);
2715
+ React.useEffect(() => {
2719
2716
  if (isSignedIn && redirectUrl) {
2720
2717
  const redirect = redirectUrl || process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_AFTER_LOGIN || "/dashboard";
2721
2718
  const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
@@ -3106,16 +3103,16 @@ var SignIn = ({ redirectUrl, appearance }) => {
3106
3103
  var SignUp = ({ redirectUrl, appearance }) => {
3107
3104
  const { signUp, isSignedIn } = useAuth2();
3108
3105
  const colors = useThemeColors();
3109
- const [name, setName] = React3.useState("");
3110
- const [email, setEmail] = React3.useState("");
3111
- const [phoneNumber, setPhoneNumber] = React3.useState("");
3112
- const [password, setPassword] = React3.useState("");
3113
- const [confirmPassword, setConfirmPassword] = React3.useState("");
3114
- const [showPassword, setShowPassword] = React3.useState(false);
3115
- const [isLoading, setIsLoading] = React3.useState(false);
3116
- const [error, setError] = React3.useState(null);
3117
- const [success, setSuccess] = React3.useState(null);
3118
- React3.useEffect(() => {
3106
+ const [name, setName] = React.useState("");
3107
+ const [email, setEmail] = React.useState("");
3108
+ const [phoneNumber, setPhoneNumber] = React.useState("");
3109
+ const [password, setPassword] = React.useState("");
3110
+ const [confirmPassword, setConfirmPassword] = React.useState("");
3111
+ const [showPassword, setShowPassword] = React.useState(false);
3112
+ const [isLoading, setIsLoading] = React.useState(false);
3113
+ const [error, setError] = React.useState(null);
3114
+ const [success, setSuccess] = React.useState(null);
3115
+ React.useEffect(() => {
3119
3116
  if (isSignedIn && redirectUrl) {
3120
3117
  const redirect = redirectUrl || process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_REGISTER || process.env.REACT_APP_AUTH_REDIRECT_AFTER_REGISTER || "/dashboard";
3121
3118
  const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
@@ -3123,23 +3120,15 @@ var SignUp = ({ redirectUrl, appearance }) => {
3123
3120
  }
3124
3121
  }, [isSignedIn, redirectUrl]);
3125
3122
  const getPasswordStrength = (pwd, colors2) => {
3126
- if (!pwd)
3127
- return { strength: "weak", color: colors2.borderSecondary };
3123
+ if (!pwd) return { strength: "weak", color: colors2.borderSecondary };
3128
3124
  let score = 0;
3129
- if (pwd.length >= 6)
3130
- score++;
3131
- if (pwd.length >= 8)
3132
- score++;
3133
- if (/[a-z]/.test(pwd) && /[A-Z]/.test(pwd))
3134
- score++;
3135
- if (/\d/.test(pwd))
3136
- score++;
3137
- if (/[^a-zA-Z\d]/.test(pwd))
3138
- score++;
3139
- if (score <= 2)
3140
- return { strength: "weak", color: colors2.errorText };
3141
- if (score <= 3)
3142
- return { strength: "medium", color: colors2.warningText || "#fa4" };
3125
+ if (pwd.length >= 6) score++;
3126
+ if (pwd.length >= 8) score++;
3127
+ if (/[a-z]/.test(pwd) && /[A-Z]/.test(pwd)) score++;
3128
+ if (/\d/.test(pwd)) score++;
3129
+ if (/[^a-zA-Z\d]/.test(pwd)) score++;
3130
+ if (score <= 2) return { strength: "weak", color: colors2.errorText };
3131
+ if (score <= 3) return { strength: "medium", color: colors2.warningText || "#fa4" };
3143
3132
  return { strength: "strong", color: colors2.successText };
3144
3133
  };
3145
3134
  const passwordStrength = getPasswordStrength(password, colors);
@@ -3160,10 +3149,8 @@ var SignUp = ({ redirectUrl, appearance }) => {
3160
3149
  }
3161
3150
  try {
3162
3151
  const signUpData = { name, password };
3163
- if (email)
3164
- signUpData.email = email;
3165
- if (phoneNumber)
3166
- signUpData.phoneNumber = phoneNumber;
3152
+ if (email) signUpData.email = email;
3153
+ if (phoneNumber) signUpData.phoneNumber = phoneNumber;
3167
3154
  const response = await signUp(signUpData);
3168
3155
  if (response.success) {
3169
3156
  setSuccess("Registration successful! Please check your email to verify your account.");
@@ -3479,7 +3466,7 @@ var SignUp = ({ redirectUrl, appearance }) => {
3479
3466
  };
3480
3467
  var SignOut = ({ redirectUrl }) => {
3481
3468
  const { signOut } = useAuth2();
3482
- React3.useEffect(() => {
3469
+ React.useEffect(() => {
3483
3470
  const performSignOut = async () => {
3484
3471
  await signOut();
3485
3472
  const redirect = redirectUrl || process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_LOGOUT || process.env.REACT_APP_AUTH_REDIRECT_AFTER_LOGOUT || "/";
@@ -3493,9 +3480,9 @@ var SignOut = ({ redirectUrl }) => {
3493
3480
  var UserButton = ({ showName = false, appearance }) => {
3494
3481
  const { user, signOut } = useAuth2();
3495
3482
  const colors = useThemeColors();
3496
- const [isOpen, setIsOpen] = React3.useState(false);
3497
- const dropdownRef = React3.useRef(null);
3498
- React3.useEffect(() => {
3483
+ const [isOpen, setIsOpen] = React.useState(false);
3484
+ const dropdownRef = React.useRef(null);
3485
+ React.useEffect(() => {
3499
3486
  const handleClickOutside = (event) => {
3500
3487
  if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
3501
3488
  setIsOpen(false);
@@ -3504,8 +3491,7 @@ var UserButton = ({ showName = false, appearance }) => {
3504
3491
  document.addEventListener("mousedown", handleClickOutside);
3505
3492
  return () => document.removeEventListener("mousedown", handleClickOutside);
3506
3493
  }, []);
3507
- if (!user)
3508
- return null;
3494
+ if (!user) return null;
3509
3495
  const getInitials = (name) => {
3510
3496
  return name.split(" ").map((n) => n[0]).join("").toUpperCase().slice(0, 2);
3511
3497
  };
@@ -3539,7 +3525,19 @@ var UserButton = ({ showName = false, appearance }) => {
3539
3525
  e.currentTarget.style.backgroundColor = "transparent";
3540
3526
  },
3541
3527
  children: [
3542
- /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
3528
+ user.avatar ? /* @__PURE__ */ jsxRuntime.jsx(
3529
+ "img",
3530
+ {
3531
+ src: user.avatar,
3532
+ alt: user.name,
3533
+ style: {
3534
+ width: "36px",
3535
+ height: "36px",
3536
+ borderRadius: "50%",
3537
+ objectFit: "cover"
3538
+ }
3539
+ }
3540
+ ) : /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
3543
3541
  width: "36px",
3544
3542
  height: "36px",
3545
3543
  borderRadius: "50%",
@@ -3576,7 +3574,19 @@ var UserButton = ({ showName = false, appearance }) => {
3576
3574
  alignItems: "center",
3577
3575
  gap: "12px"
3578
3576
  }, children: [
3579
- /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
3577
+ user.avatar ? /* @__PURE__ */ jsxRuntime.jsx(
3578
+ "img",
3579
+ {
3580
+ src: user.avatar,
3581
+ alt: user.name,
3582
+ style: {
3583
+ width: "48px",
3584
+ height: "48px",
3585
+ borderRadius: "50%",
3586
+ objectFit: "cover"
3587
+ }
3588
+ }
3589
+ ) : /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
3580
3590
  width: "48px",
3581
3591
  height: "48px",
3582
3592
  borderRadius: "50%",
@@ -3641,7 +3651,7 @@ var ProtectedRoute = ({
3641
3651
  redirectTo
3642
3652
  }) => {
3643
3653
  const { isSignedIn, isLoaded } = useAuth2();
3644
- React3.useEffect(() => {
3654
+ React.useEffect(() => {
3645
3655
  if (isLoaded && !isSignedIn) {
3646
3656
  const loginPath = redirectTo || process.env.NEXT_PUBLIC_AUTH_REDIRECT_TO_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_TO_LOGIN || "/auth/login";
3647
3657
  const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
@@ -3666,7 +3676,7 @@ var PublicRoute = ({
3666
3676
  redirectTo
3667
3677
  }) => {
3668
3678
  const { isSignedIn, isLoaded } = useAuth2();
3669
- React3.useEffect(() => {
3679
+ React.useEffect(() => {
3670
3680
  if (isLoaded && isSignedIn) {
3671
3681
  const dashboardPath = redirectTo || process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_AFTER_LOGIN || "/dashboard";
3672
3682
  const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
@@ -3688,9 +3698,9 @@ var PublicRoute = ({
3688
3698
  };
3689
3699
  var VerifyEmail = ({ token, onSuccess, onError }) => {
3690
3700
  const { verifyEmailToken } = useAuth2();
3691
- const [status, setStatus] = React3.useState("loading");
3692
- const [message, setMessage] = React3.useState("");
3693
- React3.useEffect(() => {
3701
+ const [status, setStatus] = React.useState("loading");
3702
+ const [message, setMessage] = React.useState("");
3703
+ React.useEffect(() => {
3694
3704
  const verify = async () => {
3695
3705
  const verifyToken = token || (typeof window !== "undefined" ? new URLSearchParams(window.location.search).get("token") : null);
3696
3706
  if (!verifyToken) {
@@ -3824,10 +3834,10 @@ var VerifyEmail = ({ token, onSuccess, onError }) => {
3824
3834
  };
3825
3835
  var ForgotPassword = ({ appearance }) => {
3826
3836
  const { forgotPassword } = useAuth2();
3827
- const [email, setEmail] = React3.useState("");
3828
- const [isLoading, setIsLoading] = React3.useState(false);
3829
- const [error, setError] = React3.useState(null);
3830
- const [success, setSuccess] = React3.useState(null);
3837
+ const [email, setEmail] = React.useState("");
3838
+ const [isLoading, setIsLoading] = React.useState(false);
3839
+ const [error, setError] = React.useState(null);
3840
+ const [success, setSuccess] = React.useState(null);
3831
3841
  const handleSubmit = async (e) => {
3832
3842
  e.preventDefault();
3833
3843
  setIsLoading(true);
@@ -3966,14 +3976,14 @@ var ForgotPassword = ({ appearance }) => {
3966
3976
  };
3967
3977
  var ResetPassword = ({ token, appearance }) => {
3968
3978
  const { resetPassword } = useAuth2();
3969
- const [resetToken, setResetToken] = React3.useState(token || "");
3970
- const [password, setPassword] = React3.useState("");
3971
- const [confirmPassword, setConfirmPassword] = React3.useState("");
3972
- const [showPassword, setShowPassword] = React3.useState(false);
3973
- const [isLoading, setIsLoading] = React3.useState(false);
3974
- const [error, setError] = React3.useState(null);
3975
- const [success, setSuccess] = React3.useState(false);
3976
- React3.useEffect(() => {
3979
+ const [resetToken, setResetToken] = React.useState(token || "");
3980
+ const [password, setPassword] = React.useState("");
3981
+ const [confirmPassword, setConfirmPassword] = React.useState("");
3982
+ const [showPassword, setShowPassword] = React.useState(false);
3983
+ const [isLoading, setIsLoading] = React.useState(false);
3984
+ const [error, setError] = React.useState(null);
3985
+ const [success, setSuccess] = React.useState(false);
3986
+ React.useEffect(() => {
3977
3987
  if (!resetToken && typeof window !== "undefined") {
3978
3988
  const urlToken = new URLSearchParams(window.location.search).get("token");
3979
3989
  if (urlToken) {
@@ -3982,23 +3992,15 @@ var ResetPassword = ({ token, appearance }) => {
3982
3992
  }
3983
3993
  }, [resetToken]);
3984
3994
  const getPasswordStrength = (pwd) => {
3985
- if (!pwd)
3986
- return { strength: "weak", color: "#ddd" };
3995
+ if (!pwd) return { strength: "weak", color: "#ddd" };
3987
3996
  let score = 0;
3988
- if (pwd.length >= 6)
3989
- score++;
3990
- if (pwd.length >= 8)
3991
- score++;
3992
- if (/[a-z]/.test(pwd) && /[A-Z]/.test(pwd))
3993
- score++;
3994
- if (/\d/.test(pwd))
3995
- score++;
3996
- if (/[^a-zA-Z\d]/.test(pwd))
3997
- score++;
3998
- if (score <= 2)
3999
- return { strength: "weak", color: "#f44" };
4000
- if (score <= 3)
4001
- return { strength: "medium", color: "#fa4" };
3997
+ if (pwd.length >= 6) score++;
3998
+ if (pwd.length >= 8) score++;
3999
+ if (/[a-z]/.test(pwd) && /[A-Z]/.test(pwd)) score++;
4000
+ if (/\d/.test(pwd)) score++;
4001
+ if (/[^a-zA-Z\d]/.test(pwd)) score++;
4002
+ if (score <= 2) return { strength: "weak", color: "#f44" };
4003
+ if (score <= 3) return { strength: "medium", color: "#fa4" };
4002
4004
  return { strength: "strong", color: "#4f4" };
4003
4005
  };
4004
4006
  const passwordStrength = getPasswordStrength(password);
@@ -4228,31 +4230,23 @@ var ResetPassword = ({ token, appearance }) => {
4228
4230
  };
4229
4231
  var ChangePassword = ({ onSuccess, appearance }) => {
4230
4232
  const { changePassword } = useAuth2();
4231
- const [oldPassword, setOldPassword] = React3.useState("");
4232
- const [newPassword, setNewPassword] = React3.useState("");
4233
- const [confirmPassword, setConfirmPassword] = React3.useState("");
4234
- const [showPasswords, setShowPasswords] = React3.useState(false);
4235
- const [isLoading, setIsLoading] = React3.useState(false);
4236
- const [error, setError] = React3.useState(null);
4237
- const [success, setSuccess] = React3.useState(false);
4233
+ const [oldPassword, setOldPassword] = React.useState("");
4234
+ const [newPassword, setNewPassword] = React.useState("");
4235
+ const [confirmPassword, setConfirmPassword] = React.useState("");
4236
+ const [showPasswords, setShowPasswords] = React.useState(false);
4237
+ const [isLoading, setIsLoading] = React.useState(false);
4238
+ const [error, setError] = React.useState(null);
4239
+ const [success, setSuccess] = React.useState(false);
4238
4240
  const getPasswordStrength = (pwd) => {
4239
- if (!pwd)
4240
- return { strength: "weak", color: "#ddd" };
4241
+ if (!pwd) return { strength: "weak", color: "#ddd" };
4241
4242
  let score = 0;
4242
- if (pwd.length >= 6)
4243
- score++;
4244
- if (pwd.length >= 8)
4245
- score++;
4246
- if (/[a-z]/.test(pwd) && /[A-Z]/.test(pwd))
4247
- score++;
4248
- if (/\d/.test(pwd))
4249
- score++;
4250
- if (/[^a-zA-Z\d]/.test(pwd))
4251
- score++;
4252
- if (score <= 2)
4253
- return { strength: "weak", color: "#f44" };
4254
- if (score <= 3)
4255
- return { strength: "medium", color: "#fa4" };
4243
+ if (pwd.length >= 6) score++;
4244
+ if (pwd.length >= 8) score++;
4245
+ if (/[a-z]/.test(pwd) && /[A-Z]/.test(pwd)) score++;
4246
+ if (/\d/.test(pwd)) score++;
4247
+ if (/[^a-zA-Z\d]/.test(pwd)) score++;
4248
+ if (score <= 2) return { strength: "weak", color: "#f44" };
4249
+ if (score <= 3) return { strength: "medium", color: "#fa4" };
4256
4250
  return { strength: "strong", color: "#4f4" };
4257
4251
  };
4258
4252
  const passwordStrength = getPasswordStrength(newPassword);
@@ -4483,31 +4477,21 @@ var AvatarUploader = ({
4483
4477
  buttonText = "Upload Avatar"
4484
4478
  }) => {
4485
4479
  const { uploadAndUpdateAvatar } = useAuth2();
4486
- const [open, setOpen] = React3.useState(false);
4487
- const [uploading, setUploading] = React3.useState(false);
4480
+ const [open, setOpen] = React.useState(false);
4481
+ const [uploading, setUploading] = React.useState(false);
4488
4482
  const handleSelect = async (image) => {
4489
4483
  setUploading(true);
4490
4484
  try {
4491
- const proxyUrl = `${upfilesConfig.baseUrl}/api/download?fileKey=${encodeURIComponent(image.key)}`;
4492
- const response = await fetch(proxyUrl, {
4493
- headers: upfilesConfig.apiKey ? {
4494
- [upfilesConfig.apiKeyHeader || "authorization"]: upfilesConfig.apiKey.startsWith("upk_") ? `Bearer ${upfilesConfig.apiKey}` : upfilesConfig.apiKey
4495
- } : {}
4496
- });
4497
- if (!response.ok) {
4498
- throw new Error("Failed to fetch image");
4499
- }
4500
- const blob = await response.blob();
4501
- const file = new File([blob], image.originalName, { type: image.contentType });
4502
- const result = await uploadAndUpdateAvatar(file);
4503
- if (result.success && result.user?.avatar) {
4504
- onUploadComplete?.(result.user.avatar);
4485
+ const { updateProfile } = useAuth2();
4486
+ const response = await updateProfile({ avatar: image.url });
4487
+ if (response.success && response.user?.avatar) {
4488
+ onUploadComplete?.(response.user.avatar);
4505
4489
  setOpen(false);
4506
4490
  } else {
4507
- throw new Error(result.message || "Failed to update avatar");
4491
+ throw new Error(response.message || "Failed to update avatar");
4508
4492
  }
4509
4493
  } catch (error) {
4510
- const err = error instanceof Error ? error : new Error("Upload failed");
4494
+ const err = error instanceof Error ? error : new Error("Failed to update avatar");
4511
4495
  onError?.(err);
4512
4496
  } finally {
4513
4497
  setUploading(false);
@@ -4558,12 +4542,12 @@ var UserProfile = ({
4558
4542
  }) => {
4559
4543
  const { user, updateProfile, requestEmailChange } = useAuth2();
4560
4544
  const colors = useThemeColors();
4561
- const [name, setName] = React3.useState(user?.name || "");
4562
- const [phoneNumber, setPhoneNumber] = React3.useState(user?.phoneNumber || "");
4563
- const [newEmail, setNewEmail] = React3.useState("");
4564
- const [isLoading, setIsLoading] = React3.useState(false);
4565
- const [error, setError] = React3.useState(null);
4566
- const [success, setSuccess] = React3.useState(null);
4545
+ const [name, setName] = React.useState(user?.name || "");
4546
+ const [phoneNumber, setPhoneNumber] = React.useState(user?.phoneNumber || "");
4547
+ const [newEmail, setNewEmail] = React.useState("");
4548
+ const [isLoading, setIsLoading] = React.useState(false);
4549
+ const [error, setError] = React.useState(null);
4550
+ const [success, setSuccess] = React.useState(null);
4567
4551
  const handleUpdateProfile = async (e) => {
4568
4552
  e.preventDefault();
4569
4553
  setIsLoading(true);
@@ -4620,8 +4604,7 @@ var UserProfile = ({
4620
4604
  setIsLoading(false);
4621
4605
  }
4622
4606
  };
4623
- if (!user)
4624
- return null;
4607
+ if (!user) return null;
4625
4608
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { maxWidth: "700px", margin: "0 auto", padding: "20px" }, children: [
4626
4609
  /* @__PURE__ */ jsxRuntime.jsx("h2", { style: { marginBottom: "24px", fontSize: "24px", fontWeight: 600, color: colors.textPrimary }, children: "Profile Settings" }),
4627
4610
  error && /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
@@ -4855,12 +4838,18 @@ var AvatarManager = ({
4855
4838
  gridClassName,
4856
4839
  maxFileSize = 5 * 1024 * 1024,
4857
4840
  // 5MB default
4841
+ maxFiles = 10,
4858
4842
  mode = "full",
4859
4843
  showDelete = false,
4844
+ autoRecordToDb = true,
4845
+ fetchThumbnails = true,
4846
+ projectId,
4847
+ deleteUrl,
4848
+ onDelete,
4860
4849
  upfilesConfig
4861
4850
  }) => {
4862
4851
  const { updateProfile } = useAuth2();
4863
- const [updating, setUpdating] = React3.useState(false);
4852
+ const [updating, setUpdating] = React.useState(false);
4864
4853
  const handleSelect = async (image) => {
4865
4854
  setUpdating(true);
4866
4855
  try {
@@ -4888,24 +4877,31 @@ var AvatarManager = ({
4888
4877
  apiKey: upfilesConfig.apiKey,
4889
4878
  apiKeyHeader: upfilesConfig.apiKeyHeader || "authorization",
4890
4879
  presignUrl: upfilesConfig.presignUrl,
4891
- presignPath: upfilesConfig.presignPath
4880
+ presignPath: upfilesConfig.presignPath,
4881
+ headers: upfilesConfig.headers,
4882
+ withCredentials: upfilesConfig.withCredentials
4892
4883
  },
4893
- folderPath: upfilesConfig.folderPath || "avatars/",
4884
+ projectId,
4885
+ folderPath: upfilesConfig.folderPath || "/",
4894
4886
  title,
4895
4887
  description,
4896
4888
  className,
4897
4889
  gridClassName,
4898
4890
  onSelect: handleSelect,
4891
+ onDelete,
4892
+ deleteUrl,
4893
+ autoRecordToDb,
4894
+ fetchThumbnails,
4899
4895
  maxFileSize,
4896
+ maxFiles,
4900
4897
  mode,
4901
- showDelete,
4902
- fetchThumbnails: true
4898
+ showDelete
4903
4899
  }
4904
4900
  );
4905
4901
  };
4906
4902
  var isServer = typeof window === "undefined";
4907
4903
  var useNextAuth = (config) => {
4908
- const [authService] = React3.useState(() => {
4904
+ const [authService] = React.useState(() => {
4909
4905
  const service = new AuthService(config);
4910
4906
  if (isServer && config.token) {
4911
4907
  service["token"] = config.token;
@@ -4913,10 +4909,10 @@ var useNextAuth = (config) => {
4913
4909
  }
4914
4910
  return service;
4915
4911
  });
4916
- const [user, setUser] = React3.useState(null);
4917
- const [isAuthenticated, setIsAuthenticated] = React3.useState(false);
4918
- const [loading, setLoading] = React3.useState(true);
4919
- const checkAuthStatus = React3.useCallback(() => {
4912
+ const [user, setUser] = React.useState(null);
4913
+ const [isAuthenticated, setIsAuthenticated] = React.useState(false);
4914
+ const [loading, setLoading] = React.useState(true);
4915
+ const checkAuthStatus = React.useCallback(() => {
4920
4916
  if (isServer) {
4921
4917
  const token = config.token || authService.getToken();
4922
4918
  const authenticated = !!token;
@@ -4944,10 +4940,10 @@ var useNextAuth = (config) => {
4944
4940
  }
4945
4941
  setLoading(false);
4946
4942
  }, [authService, config.token]);
4947
- React3.useEffect(() => {
4943
+ React.useEffect(() => {
4948
4944
  checkAuthStatus();
4949
4945
  }, [checkAuthStatus]);
4950
- const register = React3.useCallback(async (data) => {
4946
+ const register = React.useCallback(async (data) => {
4951
4947
  setLoading(true);
4952
4948
  try {
4953
4949
  const response = await authService.register(data);
@@ -4956,7 +4952,7 @@ var useNextAuth = (config) => {
4956
4952
  setLoading(false);
4957
4953
  }
4958
4954
  }, [authService]);
4959
- const login = React3.useCallback(async (data) => {
4955
+ const login = React.useCallback(async (data) => {
4960
4956
  setLoading(true);
4961
4957
  try {
4962
4958
  const response = await authService.login(data);
@@ -4965,7 +4961,7 @@ var useNextAuth = (config) => {
4965
4961
  setLoading(false);
4966
4962
  }
4967
4963
  }, [authService]);
4968
- const verify = React3.useCallback(async (data) => {
4964
+ const verify = React.useCallback(async (data) => {
4969
4965
  setLoading(true);
4970
4966
  try {
4971
4967
  const response = await authService.verify(data);
@@ -4978,7 +4974,7 @@ var useNextAuth = (config) => {
4978
4974
  setLoading(false);
4979
4975
  }
4980
4976
  }, [authService]);
4981
- const verifyEmailToken = React3.useCallback(async (token) => {
4977
+ const verifyEmailToken = React.useCallback(async (token) => {
4982
4978
  setLoading(true);
4983
4979
  try {
4984
4980
  const response = await authService.verifyEmailToken(token);
@@ -4991,7 +4987,7 @@ var useNextAuth = (config) => {
4991
4987
  setLoading(false);
4992
4988
  }
4993
4989
  }, [authService]);
4994
- const logout = React3.useCallback(async () => {
4990
+ const logout = React.useCallback(async () => {
4995
4991
  setLoading(true);
4996
4992
  try {
4997
4993
  await authService.logout();
@@ -5001,7 +4997,7 @@ var useNextAuth = (config) => {
5001
4997
  setLoading(false);
5002
4998
  }
5003
4999
  }, [authService]);
5004
- const updateProfile = React3.useCallback(async (data) => {
5000
+ const updateProfile = React.useCallback(async (data) => {
5005
5001
  setLoading(true);
5006
5002
  try {
5007
5003
  const response = await authService.updateProfile(data);
@@ -5013,7 +5009,7 @@ var useNextAuth = (config) => {
5013
5009
  setLoading(false);
5014
5010
  }
5015
5011
  }, [authService]);
5016
- const getProfile = React3.useCallback(async () => {
5012
+ const getProfile = React.useCallback(async () => {
5017
5013
  setLoading(true);
5018
5014
  try {
5019
5015
  const userData = await authService.getProfile();
@@ -5023,7 +5019,7 @@ var useNextAuth = (config) => {
5023
5019
  setLoading(false);
5024
5020
  }
5025
5021
  }, [authService]);
5026
- const getAllUsers = React3.useCallback(async () => {
5022
+ const getAllUsers = React.useCallback(async () => {
5027
5023
  setLoading(true);
5028
5024
  try {
5029
5025
  return await authService.getAllUsers();
@@ -5031,7 +5027,7 @@ var useNextAuth = (config) => {
5031
5027
  setLoading(false);
5032
5028
  }
5033
5029
  }, [authService]);
5034
- const getUserById = React3.useCallback(async (id) => {
5030
+ const getUserById = React.useCallback(async (id) => {
5035
5031
  setLoading(true);
5036
5032
  try {
5037
5033
  return await authService.getUserById(id);
@@ -5039,7 +5035,7 @@ var useNextAuth = (config) => {
5039
5035
  setLoading(false);
5040
5036
  }
5041
5037
  }, [authService]);
5042
- const forgotPassword = React3.useCallback(async (email) => {
5038
+ const forgotPassword = React.useCallback(async (email) => {
5043
5039
  setLoading(true);
5044
5040
  try {
5045
5041
  const response = await authService.forgotPassword(email);
@@ -5048,7 +5044,7 @@ var useNextAuth = (config) => {
5048
5044
  setLoading(false);
5049
5045
  }
5050
5046
  }, [authService]);
5051
- const resetPassword = React3.useCallback(async (token, password) => {
5047
+ const resetPassword = React.useCallback(async (token, password) => {
5052
5048
  setLoading(true);
5053
5049
  try {
5054
5050
  const response = await authService.resetPassword(token, password);
@@ -5057,7 +5053,7 @@ var useNextAuth = (config) => {
5057
5053
  setLoading(false);
5058
5054
  }
5059
5055
  }, [authService]);
5060
- const setToken = React3.useCallback((token) => {
5056
+ const setToken = React.useCallback((token) => {
5061
5057
  authService["token"] = token;
5062
5058
  authService["httpClient"].setAuthToken(token);
5063
5059
  setIsAuthenticated(true);
@@ -5069,7 +5065,7 @@ var useNextAuth = (config) => {
5069
5065
  setUser(null);
5070
5066
  }
5071
5067
  }, [authService]);
5072
- const clearToken = React3.useCallback(() => {
5068
+ const clearToken = React.useCallback(() => {
5073
5069
  authService["token"] = null;
5074
5070
  authService["httpClient"].removeAuthToken();
5075
5071
  setIsAuthenticated(false);
@@ -5122,5 +5118,5 @@ exports.useAuth = useAuth2;
5122
5118
  exports.useAuthLegacy = useAuth;
5123
5119
  exports.useAuthTheme = useAuthTheme;
5124
5120
  exports.useNextAuth = useNextAuth;
5125
- //# sourceMappingURL=out.js.map
5121
+ //# sourceMappingURL=index.next.js.map
5126
5122
  //# sourceMappingURL=index.next.js.map