@thetechfossil/auth2 1.2.15 → 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.
package/dist/index.js CHANGED
@@ -3,13 +3,13 @@
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 __defProp = Object.defineProperty;
15
15
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
@@ -74,6 +74,11 @@ var HttpClient = class {
74
74
  return Promise.reject(refreshError);
75
75
  }
76
76
  }
77
+ if (error.response && error.response.data && error.response.data.message) {
78
+ const customError = new Error(error.response.data.message);
79
+ customError.response = error.response;
80
+ return Promise.reject(customError);
81
+ }
77
82
  return Promise.reject(error);
78
83
  }
79
84
  );
@@ -510,11 +515,11 @@ var AuthService = class {
510
515
  return response;
511
516
  }
512
517
  };
513
- var ThemeContext = React3.createContext({ theme: "light", mounted: false });
518
+ var ThemeContext = React__default.default.createContext({ theme: "light", mounted: false });
514
519
  function AuthThemeProvider({ children }) {
515
- const [theme, setTheme] = React3.useState("light");
516
- const [mounted, setMounted] = React3.useState(false);
517
- React3.useEffect(() => {
520
+ const [theme, setTheme] = React.useState("light");
521
+ const [mounted, setMounted] = React.useState(false);
522
+ React.useEffect(() => {
518
523
  const detectTheme = () => {
519
524
  const htmlElement = document.documentElement;
520
525
  const bodyElement = document.body;
@@ -559,9 +564,9 @@ function AuthThemeProvider({ children }) {
559
564
  return /* @__PURE__ */ jsxRuntime.jsx(ThemeContext.Provider, { value: { theme, mounted }, children });
560
565
  }
561
566
  function useAuthTheme() {
562
- return React3.useContext(ThemeContext);
567
+ return React.useContext(ThemeContext);
563
568
  }
564
- var AuthContext = React3.createContext(void 0);
569
+ var AuthContext = React.createContext(void 0);
565
570
  var AuthProvider = ({ children, config }) => {
566
571
  const authConfig = {
567
572
  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"),
@@ -569,29 +574,35 @@ var AuthProvider = ({ children, config }) => {
569
574
  csrfEnabled: config?.csrfEnabled !== void 0 ? config.csrfEnabled : true,
570
575
  upfilesConfig: config?.upfilesConfig
571
576
  };
572
- const [authService] = React3.useState(() => new AuthService(authConfig));
573
- const [user, setUser] = React3.useState(null);
574
- const [isLoaded, setIsLoaded] = React3.useState(false);
575
- const [loading, setLoading] = React3.useState(false);
576
- const checkAuthStatus = React3.useCallback(async () => {
577
+ const [authService] = React.useState(() => new AuthService(authConfig));
578
+ const [user, setUser] = React.useState(null);
579
+ const [isLoaded, setIsLoaded] = React.useState(false);
580
+ const [loading, setLoading] = React.useState(false);
581
+ const checkAuthStatus = React.useCallback(async () => {
577
582
  const authenticated = authService.isAuthenticated();
578
583
  if (authenticated) {
579
584
  try {
580
- const currentUser = authService.getCurrentUser();
581
- setUser(currentUser);
585
+ const freshUser = await authService.getProfile();
586
+ setUser(freshUser);
582
587
  } catch (error) {
583
- console.error("Failed to get current user:", error);
584
- setUser(null);
588
+ console.error("Failed to fetch fresh user profile, falling back to token:", error);
589
+ try {
590
+ const currentUser = authService.getCurrentUser();
591
+ setUser(currentUser);
592
+ } catch (fallbackError) {
593
+ console.error("Failed to get current user from token:", fallbackError);
594
+ setUser(null);
595
+ }
585
596
  }
586
597
  } else {
587
598
  setUser(null);
588
599
  }
589
600
  setIsLoaded(true);
590
601
  }, [authService]);
591
- React3.useEffect(() => {
602
+ React.useEffect(() => {
592
603
  checkAuthStatus();
593
604
  }, [checkAuthStatus]);
594
- const signIn = React3.useCallback(async (data) => {
605
+ const signIn = React.useCallback(async (data) => {
595
606
  setLoading(true);
596
607
  try {
597
608
  const response = await authService.login(data);
@@ -603,7 +614,7 @@ var AuthProvider = ({ children, config }) => {
603
614
  setLoading(false);
604
615
  }
605
616
  }, [authService]);
606
- const signUp = React3.useCallback(async (data) => {
617
+ const signUp = React.useCallback(async (data) => {
607
618
  setLoading(true);
608
619
  try {
609
620
  const response = await authService.register(data);
@@ -612,7 +623,7 @@ var AuthProvider = ({ children, config }) => {
612
623
  setLoading(false);
613
624
  }
614
625
  }, [authService]);
615
- const signOut = React3.useCallback(async () => {
626
+ const signOut = React.useCallback(async () => {
616
627
  setLoading(true);
617
628
  try {
618
629
  await authService.logout();
@@ -621,7 +632,7 @@ var AuthProvider = ({ children, config }) => {
621
632
  setLoading(false);
622
633
  }
623
634
  }, [authService]);
624
- const verify = React3.useCallback(async (data) => {
635
+ const verify = React.useCallback(async (data) => {
625
636
  setLoading(true);
626
637
  try {
627
638
  const response = await authService.verify(data);
@@ -633,7 +644,7 @@ var AuthProvider = ({ children, config }) => {
633
644
  setLoading(false);
634
645
  }
635
646
  }, [authService]);
636
- const verifyEmailToken = React3.useCallback(async (token) => {
647
+ const verifyEmailToken = React.useCallback(async (token) => {
637
648
  setLoading(true);
638
649
  try {
639
650
  const response = await authService.verifyEmailToken(token);
@@ -645,7 +656,7 @@ var AuthProvider = ({ children, config }) => {
645
656
  setLoading(false);
646
657
  }
647
658
  }, [authService]);
648
- const updateProfile = React3.useCallback(async (data) => {
659
+ const updateProfile = React.useCallback(async (data) => {
649
660
  setLoading(true);
650
661
  try {
651
662
  const response = await authService.updateProfile(data);
@@ -657,7 +668,7 @@ var AuthProvider = ({ children, config }) => {
657
668
  setLoading(false);
658
669
  }
659
670
  }, [authService]);
660
- const getProfile = React3.useCallback(async () => {
671
+ const getProfile = React.useCallback(async () => {
661
672
  setLoading(true);
662
673
  try {
663
674
  const userData = await authService.getProfile();
@@ -667,13 +678,13 @@ var AuthProvider = ({ children, config }) => {
667
678
  setLoading(false);
668
679
  }
669
680
  }, [authService]);
670
- const signInWithOAuth = React3.useCallback((provider) => {
681
+ const signInWithOAuth = React.useCallback((provider) => {
671
682
  authService.loginWithOAuth(provider);
672
683
  }, [authService]);
673
- const linkOAuthProvider = React3.useCallback((provider) => {
684
+ const linkOAuthProvider = React.useCallback((provider) => {
674
685
  authService.linkOAuthProvider(provider);
675
686
  }, [authService]);
676
- const unlinkOAuthProvider = React3.useCallback(async (provider) => {
687
+ const unlinkOAuthProvider = React.useCallback(async (provider) => {
677
688
  setLoading(true);
678
689
  try {
679
690
  return await authService.unlinkOAuthProvider(provider);
@@ -681,7 +692,7 @@ var AuthProvider = ({ children, config }) => {
681
692
  setLoading(false);
682
693
  }
683
694
  }, [authService]);
684
- const forgotPassword = React3.useCallback(async (email) => {
695
+ const forgotPassword = React.useCallback(async (email) => {
685
696
  setLoading(true);
686
697
  try {
687
698
  return await authService.forgotPassword(email);
@@ -689,7 +700,7 @@ var AuthProvider = ({ children, config }) => {
689
700
  setLoading(false);
690
701
  }
691
702
  }, [authService]);
692
- const resetPassword = React3.useCallback(async (token, password) => {
703
+ const resetPassword = React.useCallback(async (token, password) => {
693
704
  setLoading(true);
694
705
  try {
695
706
  return await authService.resetPassword(token, password);
@@ -697,7 +708,7 @@ var AuthProvider = ({ children, config }) => {
697
708
  setLoading(false);
698
709
  }
699
710
  }, [authService]);
700
- const changePassword = React3.useCallback(async (oldPassword, newPassword) => {
711
+ const changePassword = React.useCallback(async (oldPassword, newPassword) => {
701
712
  setLoading(true);
702
713
  try {
703
714
  return await authService.changePassword(oldPassword, newPassword);
@@ -705,7 +716,7 @@ var AuthProvider = ({ children, config }) => {
705
716
  setLoading(false);
706
717
  }
707
718
  }, [authService]);
708
- const updateAvatar = React3.useCallback(async (avatar) => {
719
+ const updateAvatar = React.useCallback(async (avatar) => {
709
720
  setLoading(true);
710
721
  try {
711
722
  const response = await authService.updateAvatar(avatar);
@@ -717,7 +728,7 @@ var AuthProvider = ({ children, config }) => {
717
728
  setLoading(false);
718
729
  }
719
730
  }, [authService]);
720
- const uploadAndUpdateAvatar = React3.useCallback(async (file) => {
731
+ const uploadAndUpdateAvatar = React.useCallback(async (file) => {
721
732
  setLoading(true);
722
733
  try {
723
734
  const response = await authService.uploadAndUpdateAvatar(file);
@@ -729,7 +740,7 @@ var AuthProvider = ({ children, config }) => {
729
740
  setLoading(false);
730
741
  }
731
742
  }, [authService]);
732
- const requestEmailChange = React3.useCallback(async (newEmail) => {
743
+ const requestEmailChange = React.useCallback(async (newEmail) => {
733
744
  setLoading(true);
734
745
  try {
735
746
  return await authService.requestEmailChange(newEmail);
@@ -737,7 +748,7 @@ var AuthProvider = ({ children, config }) => {
737
748
  setLoading(false);
738
749
  }
739
750
  }, [authService]);
740
- const verifyEmailChange = React3.useCallback(async (token) => {
751
+ const verifyEmailChange = React.useCallback(async (token) => {
741
752
  setLoading(true);
742
753
  try {
743
754
  const response = await authService.verifyEmailChange(token);
@@ -749,7 +760,7 @@ var AuthProvider = ({ children, config }) => {
749
760
  setLoading(false);
750
761
  }
751
762
  }, [authService]);
752
- const generate2FA = React3.useCallback(async () => {
763
+ const generate2FA = React.useCallback(async () => {
753
764
  setLoading(true);
754
765
  try {
755
766
  return await authService.generate2FA();
@@ -757,7 +768,7 @@ var AuthProvider = ({ children, config }) => {
757
768
  setLoading(false);
758
769
  }
759
770
  }, [authService]);
760
- const enable2FA = React3.useCallback(async (token) => {
771
+ const enable2FA = React.useCallback(async (token) => {
761
772
  setLoading(true);
762
773
  try {
763
774
  return await authService.enable2FA(token);
@@ -765,7 +776,7 @@ var AuthProvider = ({ children, config }) => {
765
776
  setLoading(false);
766
777
  }
767
778
  }, [authService]);
768
- const disable2FA = React3.useCallback(async (token) => {
779
+ const disable2FA = React.useCallback(async (token) => {
769
780
  setLoading(true);
770
781
  try {
771
782
  return await authService.disable2FA(token);
@@ -773,7 +784,7 @@ var AuthProvider = ({ children, config }) => {
773
784
  setLoading(false);
774
785
  }
775
786
  }, [authService]);
776
- const validate2FA = React3.useCallback(async (token) => {
787
+ const validate2FA = React.useCallback(async (token) => {
777
788
  setLoading(true);
778
789
  try {
779
790
  return await authService.validate2FA(token);
@@ -781,7 +792,7 @@ var AuthProvider = ({ children, config }) => {
781
792
  setLoading(false);
782
793
  }
783
794
  }, [authService]);
784
- const getSessions = React3.useCallback(async () => {
795
+ const getSessions = React.useCallback(async () => {
785
796
  setLoading(true);
786
797
  try {
787
798
  return await authService.getSessions();
@@ -789,7 +800,7 @@ var AuthProvider = ({ children, config }) => {
789
800
  setLoading(false);
790
801
  }
791
802
  }, [authService]);
792
- const revokeSession = React3.useCallback(async (sessionId) => {
803
+ const revokeSession = React.useCallback(async (sessionId) => {
793
804
  setLoading(true);
794
805
  try {
795
806
  return await authService.revokeSession(sessionId);
@@ -797,7 +808,7 @@ var AuthProvider = ({ children, config }) => {
797
808
  setLoading(false);
798
809
  }
799
810
  }, [authService]);
800
- const revokeAllSessions = React3.useCallback(async () => {
811
+ const revokeAllSessions = React.useCallback(async () => {
801
812
  setLoading(true);
802
813
  try {
803
814
  const response = await authService.revokeAllSessions();
@@ -841,18 +852,18 @@ var AuthProvider = ({ children, config }) => {
841
852
  return /* @__PURE__ */ jsxRuntime.jsx(AuthContext.Provider, { value, children: /* @__PURE__ */ jsxRuntime.jsx(AuthThemeProvider, { children }) });
842
853
  };
843
854
  var useAuth = () => {
844
- const context = React3.useContext(AuthContext);
855
+ const context = React.useContext(AuthContext);
845
856
  if (context === void 0) {
846
857
  throw new Error("useAuth must be used within an AuthProvider");
847
858
  }
848
859
  return context;
849
860
  };
850
861
  var useAuth2 = (config) => {
851
- const [authService] = React3.useState(() => new AuthService(config));
852
- const [user, setUser] = React3.useState(null);
853
- const [isAuthenticated, setIsAuthenticated] = React3.useState(false);
854
- const [loading, setLoading] = React3.useState(true);
855
- const checkAuthStatus = React3.useCallback(() => {
862
+ const [authService] = React.useState(() => new AuthService(config));
863
+ const [user, setUser] = React.useState(null);
864
+ const [isAuthenticated, setIsAuthenticated] = React.useState(false);
865
+ const [loading, setLoading] = React.useState(true);
866
+ const checkAuthStatus = React.useCallback(() => {
856
867
  const authenticated = authService.isAuthenticated();
857
868
  setIsAuthenticated(authenticated);
858
869
  if (authenticated) {
@@ -863,10 +874,10 @@ var useAuth2 = (config) => {
863
874
  }
864
875
  setLoading(false);
865
876
  }, [authService]);
866
- React3.useEffect(() => {
877
+ React.useEffect(() => {
867
878
  checkAuthStatus();
868
879
  }, [checkAuthStatus]);
869
- const register = React3.useCallback(async (data) => {
880
+ const register = React.useCallback(async (data) => {
870
881
  setLoading(true);
871
882
  try {
872
883
  const response = await authService.register(data);
@@ -875,7 +886,7 @@ var useAuth2 = (config) => {
875
886
  setLoading(false);
876
887
  }
877
888
  }, [authService]);
878
- const login = React3.useCallback(async (data) => {
889
+ const login = React.useCallback(async (data) => {
879
890
  setLoading(true);
880
891
  try {
881
892
  const response = await authService.login(data);
@@ -888,7 +899,7 @@ var useAuth2 = (config) => {
888
899
  setLoading(false);
889
900
  }
890
901
  }, [authService]);
891
- const verify = React3.useCallback(async (data) => {
902
+ const verify = React.useCallback(async (data) => {
892
903
  setLoading(true);
893
904
  try {
894
905
  const response = await authService.verify(data);
@@ -901,7 +912,7 @@ var useAuth2 = (config) => {
901
912
  setLoading(false);
902
913
  }
903
914
  }, [authService]);
904
- const verifyEmailToken = React3.useCallback(async (token) => {
915
+ const verifyEmailToken = React.useCallback(async (token) => {
905
916
  setLoading(true);
906
917
  try {
907
918
  const response = await authService.verifyEmailToken(token);
@@ -914,7 +925,7 @@ var useAuth2 = (config) => {
914
925
  setLoading(false);
915
926
  }
916
927
  }, [authService]);
917
- const logout = React3.useCallback(async () => {
928
+ const logout = React.useCallback(async () => {
918
929
  setLoading(true);
919
930
  try {
920
931
  await authService.logout();
@@ -924,7 +935,7 @@ var useAuth2 = (config) => {
924
935
  setLoading(false);
925
936
  }
926
937
  }, [authService]);
927
- const updateProfile = React3.useCallback(async (data) => {
938
+ const updateProfile = React.useCallback(async (data) => {
928
939
  setLoading(true);
929
940
  try {
930
941
  const response = await authService.updateProfile(data);
@@ -936,7 +947,7 @@ var useAuth2 = (config) => {
936
947
  setLoading(false);
937
948
  }
938
949
  }, [authService]);
939
- const getProfile = React3.useCallback(async () => {
950
+ const getProfile = React.useCallback(async () => {
940
951
  setLoading(true);
941
952
  try {
942
953
  const userData = await authService.getProfile();
@@ -946,7 +957,7 @@ var useAuth2 = (config) => {
946
957
  setLoading(false);
947
958
  }
948
959
  }, [authService]);
949
- const getAllUsers = React3.useCallback(async () => {
960
+ const getAllUsers = React.useCallback(async () => {
950
961
  setLoading(true);
951
962
  try {
952
963
  return await authService.getAllUsers();
@@ -954,7 +965,7 @@ var useAuth2 = (config) => {
954
965
  setLoading(false);
955
966
  }
956
967
  }, [authService]);
957
- const getUserById = React3.useCallback(async (id) => {
968
+ const getUserById = React.useCallback(async (id) => {
958
969
  setLoading(true);
959
970
  try {
960
971
  return await authService.getUserById(id);
@@ -962,7 +973,7 @@ var useAuth2 = (config) => {
962
973
  setLoading(false);
963
974
  }
964
975
  }, [authService]);
965
- const uploadAndUpdateAvatar = React3.useCallback(async (file) => {
976
+ const uploadAndUpdateAvatar = React.useCallback(async (file) => {
966
977
  setLoading(true);
967
978
  try {
968
979
  const response = await authService.uploadAndUpdateAvatar(file);
@@ -1040,7 +1051,7 @@ try {
1040
1051
  } catch (error) {
1041
1052
  console.warn("react-phone-number-input not available, using fallback");
1042
1053
  }
1043
- var CustomPhoneInput = React3__default.default.forwardRef((props, ref) => /* @__PURE__ */ jsxRuntime.jsx(
1054
+ var CustomPhoneInput = React__default.default.forwardRef((props, ref) => /* @__PURE__ */ jsxRuntime.jsx(
1044
1055
  "input",
1045
1056
  {
1046
1057
  ...props,
@@ -1059,8 +1070,8 @@ var PhoneInput = ({
1059
1070
  style = {}
1060
1071
  }) => {
1061
1072
  const colors = useThemeColors();
1062
- const [defaultCountry, setDefaultCountry] = React3.useState("US");
1063
- const styleContent = React3.useMemo(() => `
1073
+ const [defaultCountry, setDefaultCountry] = React.useState("US");
1074
+ const styleContent = React.useMemo(() => `
1064
1075
  .PhoneInput {
1065
1076
  display: flex;
1066
1077
  align-items: center;
@@ -1172,7 +1183,7 @@ var PhoneInput = ({
1172
1183
  opacity: 0.6;
1173
1184
  }
1174
1185
  `, [colors]);
1175
- React3.useEffect(() => {
1186
+ React.useEffect(() => {
1176
1187
  const detectCountry = async () => {
1177
1188
  try {
1178
1189
  const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
@@ -1229,7 +1240,7 @@ var PhoneInput = ({
1229
1240
  };
1230
1241
  detectCountry();
1231
1242
  }, []);
1232
- const handleChange = React3.useMemo(() => (val) => {
1243
+ const handleChange = React.useMemo(() => (val) => {
1233
1244
  onChange(val || "");
1234
1245
  }, [onChange]);
1235
1246
  if (!PhoneInputWithCountry) {
@@ -1293,15 +1304,15 @@ var LoginForm = ({
1293
1304
  showOAuthButtons = true
1294
1305
  }) => {
1295
1306
  const colors = useThemeColors();
1296
- const [email, setEmail] = React3.useState("");
1297
- const [phoneNumber, setPhoneNumber] = React3.useState("");
1298
- const [usePhone, setUsePhone] = React3.useState(false);
1299
- const [password, setPassword] = React3.useState("");
1300
- const [usePassword, setUsePassword] = React3.useState(false);
1301
- const [showPassword, setShowPassword] = React3.useState(false);
1302
- const [isLoading, setIsLoading] = React3.useState(false);
1303
- const [error, setError] = React3.useState(null);
1304
- const [rememberMe, setRememberMe] = React3.useState(false);
1307
+ const [email, setEmail] = React.useState("");
1308
+ const [phoneNumber, setPhoneNumber] = React.useState("");
1309
+ const [usePhone, setUsePhone] = React.useState(false);
1310
+ const [password, setPassword] = React.useState("");
1311
+ const [usePassword, setUsePassword] = React.useState(false);
1312
+ const [showPassword, setShowPassword] = React.useState(false);
1313
+ const [isLoading, setIsLoading] = React.useState(false);
1314
+ const [error, setError] = React.useState(null);
1315
+ const [rememberMe, setRememberMe] = React.useState(false);
1305
1316
  const { login } = useAuth2({
1306
1317
  baseUrl: config?.baseUrl || "http://localhost:7000"
1307
1318
  });
@@ -1755,15 +1766,15 @@ var RegisterForm = ({
1755
1766
  invitationToken
1756
1767
  }) => {
1757
1768
  const colors = useThemeColors();
1758
- const [name, setName] = React3.useState("");
1759
- const [email, setEmail] = React3.useState("");
1760
- const [phoneNumber, setPhoneNumber] = React3.useState("");
1761
- const [password, setPassword] = React3.useState("");
1762
- const [confirmPassword, setConfirmPassword] = React3.useState("");
1763
- const [isLoading, setIsLoading] = React3.useState(false);
1764
- const [error, setError] = React3.useState(null);
1765
- const [showPassword, setShowPassword] = React3.useState(false);
1766
- const [showConfirmPassword, setShowConfirmPassword] = React3.useState(false);
1769
+ const [name, setName] = React.useState("");
1770
+ const [email, setEmail] = React.useState("");
1771
+ const [phoneNumber, setPhoneNumber] = React.useState("");
1772
+ const [password, setPassword] = React.useState("");
1773
+ const [confirmPassword, setConfirmPassword] = React.useState("");
1774
+ const [isLoading, setIsLoading] = React.useState(false);
1775
+ const [error, setError] = React.useState(null);
1776
+ const [showPassword, setShowPassword] = React.useState(false);
1777
+ const [showConfirmPassword, setShowConfirmPassword] = React.useState(false);
1767
1778
  const getPasswordStrength = (pwd) => {
1768
1779
  if (!pwd) return { strength: "weak", score: 0, label: "" };
1769
1780
  let score = 0;
@@ -2219,11 +2230,11 @@ var OtpForm = ({
2219
2230
  baseUrl
2220
2231
  }) => {
2221
2232
  const colors = useThemeColors();
2222
- const [otp, setOtp] = React3.useState("");
2223
- const [isLoading, setIsLoading] = React3.useState(false);
2224
- const [error, setError] = React3.useState(null);
2225
- const [resendCooldown, setResendCooldown] = React3.useState(0);
2226
- const [resendLoading, setResendLoading] = React3.useState(false);
2233
+ const [otp, setOtp] = React.useState("");
2234
+ const [isLoading, setIsLoading] = React.useState(false);
2235
+ const [error, setError] = React.useState(null);
2236
+ const [resendCooldown, setResendCooldown] = React.useState(0);
2237
+ const [resendLoading, setResendLoading] = React.useState(false);
2227
2238
  const { verify, login } = useAuth2({
2228
2239
  baseUrl: baseUrl || process.env.NEXT_PUBLIC_AUTH_API_URL || "http://localhost:7000"
2229
2240
  });
@@ -2434,9 +2445,9 @@ var AuthFlow = ({
2434
2445
  initialStep = "login",
2435
2446
  showTitle = true
2436
2447
  }) => {
2437
- const [step, setStep] = React3.useState(initialStep);
2438
- const [email, setEmail] = React3.useState("");
2439
- const [message, setMessage] = React3.useState(null);
2448
+ const [step, setStep] = React.useState(initialStep);
2449
+ const [email, setEmail] = React.useState("");
2450
+ const [message, setMessage] = React.useState(null);
2440
2451
  const handleLoginSuccess = (email2, needsOtpVerification) => {
2441
2452
  setEmail(email2);
2442
2453
  if (needsOtpVerification) {
@@ -2571,13 +2582,13 @@ var EmailVerificationPage = ({
2571
2582
  onVerificationError,
2572
2583
  baseUrl
2573
2584
  }) => {
2574
- const [isLoading, setIsLoading] = React3.useState(true);
2575
- const [message, setMessage] = React3.useState("");
2576
- const [isSuccess, setIsSuccess] = React3.useState(false);
2585
+ const [isLoading, setIsLoading] = React.useState(true);
2586
+ const [message, setMessage] = React.useState("");
2587
+ const [isSuccess, setIsSuccess] = React.useState(false);
2577
2588
  const { verifyEmailToken } = useAuth2({
2578
2589
  baseUrl: baseUrl || (typeof window !== "undefined" ? window.location.origin : "http://localhost:7000")
2579
2590
  });
2580
- React3.useEffect(() => {
2591
+ React.useEffect(() => {
2581
2592
  const verifyEmail = async () => {
2582
2593
  if (!token) {
2583
2594
  setIsLoading(false);
@@ -2682,7 +2693,7 @@ var EmailVerificationPage = ({
2682
2693
  ] })
2683
2694
  ] }) });
2684
2695
  };
2685
- var ThemeWrapper = React3.forwardRef(
2696
+ var ThemeWrapper = React.forwardRef(
2686
2697
  ({ children, className = "", style }, ref) => {
2687
2698
  const { theme, mounted } = useAuthTheme();
2688
2699
  if (!mounted) {
@@ -2695,18 +2706,18 @@ ThemeWrapper.displayName = "ThemeWrapper";
2695
2706
  var SignIn = ({ redirectUrl, appearance }) => {
2696
2707
  const { signIn, isSignedIn, loading: authLoading } = useAuth();
2697
2708
  const colors = useThemeColors();
2698
- const [email, setEmail] = React3.useState("");
2699
- const [phoneNumber, setPhoneNumber] = React3.useState("");
2700
- const [password, setPassword] = React3.useState("");
2701
- const [otp, setOtp] = React3.useState("");
2702
- const [usePassword, setUsePassword] = React3.useState(false);
2703
- const [usePhone, setUsePhone] = React3.useState(false);
2704
- const [showPassword, setShowPassword] = React3.useState(false);
2705
- const [isLoading, setIsLoading] = React3.useState(false);
2706
- const [error, setError] = React3.useState(null);
2707
- const [needsOtp, setNeedsOtp] = React3.useState(false);
2708
- const [success, setSuccess] = React3.useState(null);
2709
- React3.useEffect(() => {
2709
+ const [email, setEmail] = React.useState("");
2710
+ const [phoneNumber, setPhoneNumber] = React.useState("");
2711
+ const [password, setPassword] = React.useState("");
2712
+ const [otp, setOtp] = React.useState("");
2713
+ const [usePassword, setUsePassword] = React.useState(false);
2714
+ const [usePhone, setUsePhone] = React.useState(false);
2715
+ const [showPassword, setShowPassword] = React.useState(false);
2716
+ const [isLoading, setIsLoading] = React.useState(false);
2717
+ const [error, setError] = React.useState(null);
2718
+ const [needsOtp, setNeedsOtp] = React.useState(false);
2719
+ const [success, setSuccess] = React.useState(null);
2720
+ React.useEffect(() => {
2710
2721
  if (isSignedIn && redirectUrl) {
2711
2722
  const redirect = redirectUrl || process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_AFTER_LOGIN || "/dashboard";
2712
2723
  const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
@@ -3097,16 +3108,16 @@ var SignIn = ({ redirectUrl, appearance }) => {
3097
3108
  var SignUp = ({ redirectUrl, appearance }) => {
3098
3109
  const { signUp, isSignedIn } = useAuth();
3099
3110
  const colors = useThemeColors();
3100
- const [name, setName] = React3.useState("");
3101
- const [email, setEmail] = React3.useState("");
3102
- const [phoneNumber, setPhoneNumber] = React3.useState("");
3103
- const [password, setPassword] = React3.useState("");
3104
- const [confirmPassword, setConfirmPassword] = React3.useState("");
3105
- const [showPassword, setShowPassword] = React3.useState(false);
3106
- const [isLoading, setIsLoading] = React3.useState(false);
3107
- const [error, setError] = React3.useState(null);
3108
- const [success, setSuccess] = React3.useState(null);
3109
- React3.useEffect(() => {
3111
+ const [name, setName] = React.useState("");
3112
+ const [email, setEmail] = React.useState("");
3113
+ const [phoneNumber, setPhoneNumber] = React.useState("");
3114
+ const [password, setPassword] = React.useState("");
3115
+ const [confirmPassword, setConfirmPassword] = React.useState("");
3116
+ const [showPassword, setShowPassword] = React.useState(false);
3117
+ const [isLoading, setIsLoading] = React.useState(false);
3118
+ const [error, setError] = React.useState(null);
3119
+ const [success, setSuccess] = React.useState(null);
3120
+ React.useEffect(() => {
3110
3121
  if (isSignedIn && redirectUrl) {
3111
3122
  const redirect = redirectUrl || process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_REGISTER || process.env.REACT_APP_AUTH_REDIRECT_AFTER_REGISTER || "/dashboard";
3112
3123
  const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
@@ -3460,7 +3471,7 @@ var SignUp = ({ redirectUrl, appearance }) => {
3460
3471
  };
3461
3472
  var SignOut = ({ redirectUrl }) => {
3462
3473
  const { signOut } = useAuth();
3463
- React3.useEffect(() => {
3474
+ React.useEffect(() => {
3464
3475
  const performSignOut = async () => {
3465
3476
  await signOut();
3466
3477
  const redirect = redirectUrl || process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_LOGOUT || process.env.REACT_APP_AUTH_REDIRECT_AFTER_LOGOUT || "/";
@@ -3474,9 +3485,9 @@ var SignOut = ({ redirectUrl }) => {
3474
3485
  var UserButton = ({ showName = false, appearance }) => {
3475
3486
  const { user, signOut } = useAuth();
3476
3487
  const colors = useThemeColors();
3477
- const [isOpen, setIsOpen] = React3.useState(false);
3478
- const dropdownRef = React3.useRef(null);
3479
- React3.useEffect(() => {
3488
+ const [isOpen, setIsOpen] = React.useState(false);
3489
+ const dropdownRef = React.useRef(null);
3490
+ React.useEffect(() => {
3480
3491
  const handleClickOutside = (event) => {
3481
3492
  if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
3482
3493
  setIsOpen(false);
@@ -3519,7 +3530,19 @@ var UserButton = ({ showName = false, appearance }) => {
3519
3530
  e.currentTarget.style.backgroundColor = "transparent";
3520
3531
  },
3521
3532
  children: [
3522
- /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
3533
+ user.avatar ? /* @__PURE__ */ jsxRuntime.jsx(
3534
+ "img",
3535
+ {
3536
+ src: user.avatar,
3537
+ alt: user.name,
3538
+ style: {
3539
+ width: "36px",
3540
+ height: "36px",
3541
+ borderRadius: "50%",
3542
+ objectFit: "cover"
3543
+ }
3544
+ }
3545
+ ) : /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
3523
3546
  width: "36px",
3524
3547
  height: "36px",
3525
3548
  borderRadius: "50%",
@@ -3556,7 +3579,19 @@ var UserButton = ({ showName = false, appearance }) => {
3556
3579
  alignItems: "center",
3557
3580
  gap: "12px"
3558
3581
  }, children: [
3559
- /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
3582
+ user.avatar ? /* @__PURE__ */ jsxRuntime.jsx(
3583
+ "img",
3584
+ {
3585
+ src: user.avatar,
3586
+ alt: user.name,
3587
+ style: {
3588
+ width: "48px",
3589
+ height: "48px",
3590
+ borderRadius: "50%",
3591
+ objectFit: "cover"
3592
+ }
3593
+ }
3594
+ ) : /* @__PURE__ */ jsxRuntime.jsx("div", { style: {
3560
3595
  width: "48px",
3561
3596
  height: "48px",
3562
3597
  borderRadius: "50%",
@@ -3621,7 +3656,7 @@ var ProtectedRoute = ({
3621
3656
  redirectTo
3622
3657
  }) => {
3623
3658
  const { isSignedIn, isLoaded } = useAuth();
3624
- React3.useEffect(() => {
3659
+ React.useEffect(() => {
3625
3660
  if (isLoaded && !isSignedIn) {
3626
3661
  const loginPath = redirectTo || process.env.NEXT_PUBLIC_AUTH_REDIRECT_TO_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_TO_LOGIN || "/auth/login";
3627
3662
  const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
@@ -3646,7 +3681,7 @@ var PublicRoute = ({
3646
3681
  redirectTo
3647
3682
  }) => {
3648
3683
  const { isSignedIn, isLoaded } = useAuth();
3649
- React3.useEffect(() => {
3684
+ React.useEffect(() => {
3650
3685
  if (isLoaded && isSignedIn) {
3651
3686
  const dashboardPath = redirectTo || process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_AFTER_LOGIN || "/dashboard";
3652
3687
  const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
@@ -3668,9 +3703,9 @@ var PublicRoute = ({
3668
3703
  };
3669
3704
  var VerifyEmail = ({ token, onSuccess, onError }) => {
3670
3705
  const { verifyEmailToken } = useAuth();
3671
- const [status, setStatus] = React3.useState("loading");
3672
- const [message, setMessage] = React3.useState("");
3673
- React3.useEffect(() => {
3706
+ const [status, setStatus] = React.useState("loading");
3707
+ const [message, setMessage] = React.useState("");
3708
+ React.useEffect(() => {
3674
3709
  const verify = async () => {
3675
3710
  const verifyToken = token || (typeof window !== "undefined" ? new URLSearchParams(window.location.search).get("token") : null);
3676
3711
  if (!verifyToken) {
@@ -3804,10 +3839,10 @@ var VerifyEmail = ({ token, onSuccess, onError }) => {
3804
3839
  };
3805
3840
  var ForgotPassword = ({ appearance }) => {
3806
3841
  const { forgotPassword } = useAuth();
3807
- const [email, setEmail] = React3.useState("");
3808
- const [isLoading, setIsLoading] = React3.useState(false);
3809
- const [error, setError] = React3.useState(null);
3810
- const [success, setSuccess] = React3.useState(null);
3842
+ const [email, setEmail] = React.useState("");
3843
+ const [isLoading, setIsLoading] = React.useState(false);
3844
+ const [error, setError] = React.useState(null);
3845
+ const [success, setSuccess] = React.useState(null);
3811
3846
  const handleSubmit = async (e) => {
3812
3847
  e.preventDefault();
3813
3848
  setIsLoading(true);
@@ -3946,14 +3981,14 @@ var ForgotPassword = ({ appearance }) => {
3946
3981
  };
3947
3982
  var ResetPassword = ({ token, appearance }) => {
3948
3983
  const { resetPassword } = useAuth();
3949
- const [resetToken, setResetToken] = React3.useState(token || "");
3950
- const [password, setPassword] = React3.useState("");
3951
- const [confirmPassword, setConfirmPassword] = React3.useState("");
3952
- const [showPassword, setShowPassword] = React3.useState(false);
3953
- const [isLoading, setIsLoading] = React3.useState(false);
3954
- const [error, setError] = React3.useState(null);
3955
- const [success, setSuccess] = React3.useState(false);
3956
- React3.useEffect(() => {
3984
+ const [resetToken, setResetToken] = React.useState(token || "");
3985
+ const [password, setPassword] = React.useState("");
3986
+ const [confirmPassword, setConfirmPassword] = React.useState("");
3987
+ const [showPassword, setShowPassword] = React.useState(false);
3988
+ const [isLoading, setIsLoading] = React.useState(false);
3989
+ const [error, setError] = React.useState(null);
3990
+ const [success, setSuccess] = React.useState(false);
3991
+ React.useEffect(() => {
3957
3992
  if (!resetToken && typeof window !== "undefined") {
3958
3993
  const urlToken = new URLSearchParams(window.location.search).get("token");
3959
3994
  if (urlToken) {
@@ -4200,13 +4235,13 @@ var ResetPassword = ({ token, appearance }) => {
4200
4235
  };
4201
4236
  var ChangePassword = ({ onSuccess, appearance }) => {
4202
4237
  const { changePassword } = useAuth();
4203
- const [oldPassword, setOldPassword] = React3.useState("");
4204
- const [newPassword, setNewPassword] = React3.useState("");
4205
- const [confirmPassword, setConfirmPassword] = React3.useState("");
4206
- const [showPasswords, setShowPasswords] = React3.useState(false);
4207
- const [isLoading, setIsLoading] = React3.useState(false);
4208
- const [error, setError] = React3.useState(null);
4209
- const [success, setSuccess] = React3.useState(false);
4238
+ const [oldPassword, setOldPassword] = React.useState("");
4239
+ const [newPassword, setNewPassword] = React.useState("");
4240
+ const [confirmPassword, setConfirmPassword] = React.useState("");
4241
+ const [showPasswords, setShowPasswords] = React.useState(false);
4242
+ const [isLoading, setIsLoading] = React.useState(false);
4243
+ const [error, setError] = React.useState(null);
4244
+ const [success, setSuccess] = React.useState(false);
4210
4245
  const getPasswordStrength = (pwd) => {
4211
4246
  if (!pwd) return { strength: "weak", color: "#ddd" };
4212
4247
  let score = 0;
@@ -4447,31 +4482,21 @@ var AvatarUploader = ({
4447
4482
  buttonText = "Upload Avatar"
4448
4483
  }) => {
4449
4484
  const { uploadAndUpdateAvatar } = useAuth();
4450
- const [open, setOpen] = React3.useState(false);
4451
- const [uploading, setUploading] = React3.useState(false);
4485
+ const [open, setOpen] = React.useState(false);
4486
+ const [uploading, setUploading] = React.useState(false);
4452
4487
  const handleSelect = async (image) => {
4453
4488
  setUploading(true);
4454
4489
  try {
4455
- const proxyUrl = `${upfilesConfig.baseUrl}/api/download?fileKey=${encodeURIComponent(image.key)}`;
4456
- const response = await fetch(proxyUrl, {
4457
- headers: upfilesConfig.apiKey ? {
4458
- [upfilesConfig.apiKeyHeader || "authorization"]: upfilesConfig.apiKey.startsWith("upk_") ? `Bearer ${upfilesConfig.apiKey}` : upfilesConfig.apiKey
4459
- } : {}
4460
- });
4461
- if (!response.ok) {
4462
- throw new Error("Failed to fetch image");
4463
- }
4464
- const blob = await response.blob();
4465
- const file = new File([blob], image.originalName, { type: image.contentType });
4466
- const result = await uploadAndUpdateAvatar(file);
4467
- if (result.success && result.user?.avatar) {
4468
- onUploadComplete?.(result.user.avatar);
4490
+ const { updateProfile } = useAuth();
4491
+ const response = await updateProfile({ avatar: image.url });
4492
+ if (response.success && response.user?.avatar) {
4493
+ onUploadComplete?.(response.user.avatar);
4469
4494
  setOpen(false);
4470
4495
  } else {
4471
- throw new Error(result.message || "Failed to update avatar");
4496
+ throw new Error(response.message || "Failed to update avatar");
4472
4497
  }
4473
4498
  } catch (error) {
4474
- const err = error instanceof Error ? error : new Error("Upload failed");
4499
+ const err = error instanceof Error ? error : new Error("Failed to update avatar");
4475
4500
  onError?.(err);
4476
4501
  } finally {
4477
4502
  setUploading(false);
@@ -4522,12 +4547,12 @@ var UserProfile = ({
4522
4547
  }) => {
4523
4548
  const { user, updateProfile, requestEmailChange } = useAuth();
4524
4549
  const colors = useThemeColors();
4525
- const [name, setName] = React3.useState(user?.name || "");
4526
- const [phoneNumber, setPhoneNumber] = React3.useState(user?.phoneNumber || "");
4527
- const [newEmail, setNewEmail] = React3.useState("");
4528
- const [isLoading, setIsLoading] = React3.useState(false);
4529
- const [error, setError] = React3.useState(null);
4530
- const [success, setSuccess] = React3.useState(null);
4550
+ const [name, setName] = React.useState(user?.name || "");
4551
+ const [phoneNumber, setPhoneNumber] = React.useState(user?.phoneNumber || "");
4552
+ const [newEmail, setNewEmail] = React.useState("");
4553
+ const [isLoading, setIsLoading] = React.useState(false);
4554
+ const [error, setError] = React.useState(null);
4555
+ const [success, setSuccess] = React.useState(null);
4531
4556
  const handleUpdateProfile = async (e) => {
4532
4557
  e.preventDefault();
4533
4558
  setIsLoading(true);
@@ -4818,12 +4843,18 @@ var AvatarManager = ({
4818
4843
  gridClassName,
4819
4844
  maxFileSize = 5 * 1024 * 1024,
4820
4845
  // 5MB default
4846
+ maxFiles = 10,
4821
4847
  mode = "full",
4822
4848
  showDelete = false,
4849
+ autoRecordToDb = true,
4850
+ fetchThumbnails = true,
4851
+ projectId,
4852
+ deleteUrl,
4853
+ onDelete,
4823
4854
  upfilesConfig
4824
4855
  }) => {
4825
4856
  const { updateProfile } = useAuth();
4826
- const [updating, setUpdating] = React3.useState(false);
4857
+ const [updating, setUpdating] = React.useState(false);
4827
4858
  const handleSelect = async (image) => {
4828
4859
  setUpdating(true);
4829
4860
  try {
@@ -4851,18 +4882,25 @@ var AvatarManager = ({
4851
4882
  apiKey: upfilesConfig.apiKey,
4852
4883
  apiKeyHeader: upfilesConfig.apiKeyHeader || "authorization",
4853
4884
  presignUrl: upfilesConfig.presignUrl,
4854
- presignPath: upfilesConfig.presignPath
4885
+ presignPath: upfilesConfig.presignPath,
4886
+ headers: upfilesConfig.headers,
4887
+ withCredentials: upfilesConfig.withCredentials
4855
4888
  },
4856
- folderPath: upfilesConfig.folderPath || "avatars/",
4889
+ projectId,
4890
+ folderPath: upfilesConfig.folderPath || "/",
4857
4891
  title,
4858
4892
  description,
4859
4893
  className,
4860
4894
  gridClassName,
4861
4895
  onSelect: handleSelect,
4896
+ onDelete,
4897
+ deleteUrl,
4898
+ autoRecordToDb,
4899
+ fetchThumbnails,
4862
4900
  maxFileSize,
4901
+ maxFiles,
4863
4902
  mode,
4864
- showDelete,
4865
- fetchThumbnails: true
4903
+ showDelete
4866
4904
  }
4867
4905
  );
4868
4906
  };