@thetechfossil/auth2 1.2.15 → 1.2.17
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/README.md +0 -0
- package/dist/index.components.d.mts +8 -0
- package/dist/index.components.d.ts +8 -0
- package/dist/index.components.js +253 -142
- package/dist/index.components.js.map +1 -1
- package/dist/index.components.mjs +139 -28
- package/dist/index.components.mjs.map +1 -1
- package/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +296 -179
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +149 -32
- package/dist/index.mjs.map +1 -1
- package/dist/index.next.d.mts +8 -0
- package/dist/index.next.d.ts +8 -0
- package/dist/index.next.js +315 -198
- package/dist/index.next.js.map +1 -1
- package/dist/index.next.mjs +149 -32
- package/dist/index.next.mjs.map +1 -1
- package/dist/index.next.server.d.mts +15 -3
- package/dist/index.next.server.d.ts +15 -3
- package/dist/index.next.server.js +21 -5
- package/dist/index.next.server.js.map +1 -1
- package/dist/index.next.server.mjs +18 -2
- package/dist/index.next.server.mjs.map +1 -1
- package/dist/index.node.js +5 -0
- package/dist/index.node.js.map +1 -1
- package/dist/index.node.mjs +5 -0
- package/dist/index.node.mjs.map +1 -1
- package/next/index.js +0 -0
- package/next/index.mjs +0 -0
- package/next/package.json +0 -0
- package/next/server/package.json +0 -0
- package/next/server.js +0 -0
- package/next/server.mjs +0 -0
- package/package.json +102 -101
package/dist/index.next.js
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
|
|
4
4
|
var axios = require('axios');
|
|
5
5
|
var upfiles = require('@thetechfossil/upfiles');
|
|
6
|
-
var
|
|
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
|
|
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]
|
|
@@ -69,6 +69,11 @@ var HttpClient = class {
|
|
|
69
69
|
return Promise.reject(refreshError);
|
|
70
70
|
}
|
|
71
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
|
+
}
|
|
72
77
|
return Promise.reject(error);
|
|
73
78
|
}
|
|
74
79
|
);
|
|
@@ -506,11 +511,11 @@ var AuthService = class {
|
|
|
506
511
|
}
|
|
507
512
|
};
|
|
508
513
|
var useAuth = (config) => {
|
|
509
|
-
const [authService] =
|
|
510
|
-
const [user, setUser] =
|
|
511
|
-
const [isAuthenticated, setIsAuthenticated] =
|
|
512
|
-
const [loading, setLoading] =
|
|
513
|
-
const checkAuthStatus =
|
|
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(() => {
|
|
514
519
|
const authenticated = authService.isAuthenticated();
|
|
515
520
|
setIsAuthenticated(authenticated);
|
|
516
521
|
if (authenticated) {
|
|
@@ -521,10 +526,10 @@ var useAuth = (config) => {
|
|
|
521
526
|
}
|
|
522
527
|
setLoading(false);
|
|
523
528
|
}, [authService]);
|
|
524
|
-
|
|
529
|
+
React.useEffect(() => {
|
|
525
530
|
checkAuthStatus();
|
|
526
531
|
}, [checkAuthStatus]);
|
|
527
|
-
const register =
|
|
532
|
+
const register = React.useCallback(async (data) => {
|
|
528
533
|
setLoading(true);
|
|
529
534
|
try {
|
|
530
535
|
const response = await authService.register(data);
|
|
@@ -533,7 +538,7 @@ var useAuth = (config) => {
|
|
|
533
538
|
setLoading(false);
|
|
534
539
|
}
|
|
535
540
|
}, [authService]);
|
|
536
|
-
const login =
|
|
541
|
+
const login = React.useCallback(async (data) => {
|
|
537
542
|
setLoading(true);
|
|
538
543
|
try {
|
|
539
544
|
const response = await authService.login(data);
|
|
@@ -546,7 +551,7 @@ var useAuth = (config) => {
|
|
|
546
551
|
setLoading(false);
|
|
547
552
|
}
|
|
548
553
|
}, [authService]);
|
|
549
|
-
const verify =
|
|
554
|
+
const verify = React.useCallback(async (data) => {
|
|
550
555
|
setLoading(true);
|
|
551
556
|
try {
|
|
552
557
|
const response = await authService.verify(data);
|
|
@@ -559,7 +564,7 @@ var useAuth = (config) => {
|
|
|
559
564
|
setLoading(false);
|
|
560
565
|
}
|
|
561
566
|
}, [authService]);
|
|
562
|
-
const verifyEmailToken =
|
|
567
|
+
const verifyEmailToken = React.useCallback(async (token) => {
|
|
563
568
|
setLoading(true);
|
|
564
569
|
try {
|
|
565
570
|
const response = await authService.verifyEmailToken(token);
|
|
@@ -572,7 +577,7 @@ var useAuth = (config) => {
|
|
|
572
577
|
setLoading(false);
|
|
573
578
|
}
|
|
574
579
|
}, [authService]);
|
|
575
|
-
const logout =
|
|
580
|
+
const logout = React.useCallback(async () => {
|
|
576
581
|
setLoading(true);
|
|
577
582
|
try {
|
|
578
583
|
await authService.logout();
|
|
@@ -582,7 +587,7 @@ var useAuth = (config) => {
|
|
|
582
587
|
setLoading(false);
|
|
583
588
|
}
|
|
584
589
|
}, [authService]);
|
|
585
|
-
const updateProfile =
|
|
590
|
+
const updateProfile = React.useCallback(async (data) => {
|
|
586
591
|
setLoading(true);
|
|
587
592
|
try {
|
|
588
593
|
const response = await authService.updateProfile(data);
|
|
@@ -594,7 +599,7 @@ var useAuth = (config) => {
|
|
|
594
599
|
setLoading(false);
|
|
595
600
|
}
|
|
596
601
|
}, [authService]);
|
|
597
|
-
const getProfile =
|
|
602
|
+
const getProfile = React.useCallback(async () => {
|
|
598
603
|
setLoading(true);
|
|
599
604
|
try {
|
|
600
605
|
const userData = await authService.getProfile();
|
|
@@ -604,7 +609,7 @@ var useAuth = (config) => {
|
|
|
604
609
|
setLoading(false);
|
|
605
610
|
}
|
|
606
611
|
}, [authService]);
|
|
607
|
-
const getAllUsers =
|
|
612
|
+
const getAllUsers = React.useCallback(async () => {
|
|
608
613
|
setLoading(true);
|
|
609
614
|
try {
|
|
610
615
|
return await authService.getAllUsers();
|
|
@@ -612,7 +617,7 @@ var useAuth = (config) => {
|
|
|
612
617
|
setLoading(false);
|
|
613
618
|
}
|
|
614
619
|
}, [authService]);
|
|
615
|
-
const getUserById =
|
|
620
|
+
const getUserById = React.useCallback(async (id) => {
|
|
616
621
|
setLoading(true);
|
|
617
622
|
try {
|
|
618
623
|
return await authService.getUserById(id);
|
|
@@ -620,7 +625,7 @@ var useAuth = (config) => {
|
|
|
620
625
|
setLoading(false);
|
|
621
626
|
}
|
|
622
627
|
}, [authService]);
|
|
623
|
-
const uploadAndUpdateAvatar =
|
|
628
|
+
const uploadAndUpdateAvatar = React.useCallback(async (file) => {
|
|
624
629
|
setLoading(true);
|
|
625
630
|
try {
|
|
626
631
|
const response = await authService.uploadAndUpdateAvatar(file);
|
|
@@ -648,11 +653,11 @@ var useAuth = (config) => {
|
|
|
648
653
|
uploadAndUpdateAvatar
|
|
649
654
|
};
|
|
650
655
|
};
|
|
651
|
-
var ThemeContext =
|
|
656
|
+
var ThemeContext = React__default.default.createContext({ theme: "light", mounted: false });
|
|
652
657
|
function AuthThemeProvider({ children }) {
|
|
653
|
-
const [theme, setTheme] =
|
|
654
|
-
const [mounted, setMounted] =
|
|
655
|
-
|
|
658
|
+
const [theme, setTheme] = React.useState("light");
|
|
659
|
+
const [mounted, setMounted] = React.useState(false);
|
|
660
|
+
React.useEffect(() => {
|
|
656
661
|
const detectTheme = () => {
|
|
657
662
|
const htmlElement = document.documentElement;
|
|
658
663
|
const bodyElement = document.body;
|
|
@@ -697,9 +702,9 @@ function AuthThemeProvider({ children }) {
|
|
|
697
702
|
return /* @__PURE__ */ jsxRuntime.jsx(ThemeContext.Provider, { value: { theme, mounted }, children });
|
|
698
703
|
}
|
|
699
704
|
function useAuthTheme() {
|
|
700
|
-
return
|
|
705
|
+
return React.useContext(ThemeContext);
|
|
701
706
|
}
|
|
702
|
-
var AuthContext =
|
|
707
|
+
var AuthContext = React.createContext(void 0);
|
|
703
708
|
var AuthProvider = ({ children, config }) => {
|
|
704
709
|
const authConfig = {
|
|
705
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"),
|
|
@@ -707,29 +712,35 @@ var AuthProvider = ({ children, config }) => {
|
|
|
707
712
|
csrfEnabled: config?.csrfEnabled !== void 0 ? config.csrfEnabled : true,
|
|
708
713
|
upfilesConfig: config?.upfilesConfig
|
|
709
714
|
};
|
|
710
|
-
const [authService] =
|
|
711
|
-
const [user, setUser] =
|
|
712
|
-
const [isLoaded, setIsLoaded] =
|
|
713
|
-
const [loading, setLoading] =
|
|
714
|
-
const checkAuthStatus =
|
|
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 () => {
|
|
715
720
|
const authenticated = authService.isAuthenticated();
|
|
716
721
|
if (authenticated) {
|
|
717
722
|
try {
|
|
718
|
-
const
|
|
719
|
-
setUser(
|
|
723
|
+
const freshUser = await authService.getProfile();
|
|
724
|
+
setUser(freshUser);
|
|
720
725
|
} catch (error) {
|
|
721
|
-
console.error("Failed to
|
|
722
|
-
|
|
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
|
+
}
|
|
723
734
|
}
|
|
724
735
|
} else {
|
|
725
736
|
setUser(null);
|
|
726
737
|
}
|
|
727
738
|
setIsLoaded(true);
|
|
728
739
|
}, [authService]);
|
|
729
|
-
|
|
740
|
+
React.useEffect(() => {
|
|
730
741
|
checkAuthStatus();
|
|
731
742
|
}, [checkAuthStatus]);
|
|
732
|
-
const signIn =
|
|
743
|
+
const signIn = React.useCallback(async (data) => {
|
|
733
744
|
setLoading(true);
|
|
734
745
|
try {
|
|
735
746
|
const response = await authService.login(data);
|
|
@@ -741,7 +752,7 @@ var AuthProvider = ({ children, config }) => {
|
|
|
741
752
|
setLoading(false);
|
|
742
753
|
}
|
|
743
754
|
}, [authService]);
|
|
744
|
-
const signUp =
|
|
755
|
+
const signUp = React.useCallback(async (data) => {
|
|
745
756
|
setLoading(true);
|
|
746
757
|
try {
|
|
747
758
|
const response = await authService.register(data);
|
|
@@ -750,7 +761,7 @@ var AuthProvider = ({ children, config }) => {
|
|
|
750
761
|
setLoading(false);
|
|
751
762
|
}
|
|
752
763
|
}, [authService]);
|
|
753
|
-
const signOut =
|
|
764
|
+
const signOut = React.useCallback(async () => {
|
|
754
765
|
setLoading(true);
|
|
755
766
|
try {
|
|
756
767
|
await authService.logout();
|
|
@@ -759,7 +770,7 @@ var AuthProvider = ({ children, config }) => {
|
|
|
759
770
|
setLoading(false);
|
|
760
771
|
}
|
|
761
772
|
}, [authService]);
|
|
762
|
-
const verify =
|
|
773
|
+
const verify = React.useCallback(async (data) => {
|
|
763
774
|
setLoading(true);
|
|
764
775
|
try {
|
|
765
776
|
const response = await authService.verify(data);
|
|
@@ -771,7 +782,7 @@ var AuthProvider = ({ children, config }) => {
|
|
|
771
782
|
setLoading(false);
|
|
772
783
|
}
|
|
773
784
|
}, [authService]);
|
|
774
|
-
const verifyEmailToken =
|
|
785
|
+
const verifyEmailToken = React.useCallback(async (token) => {
|
|
775
786
|
setLoading(true);
|
|
776
787
|
try {
|
|
777
788
|
const response = await authService.verifyEmailToken(token);
|
|
@@ -783,7 +794,7 @@ var AuthProvider = ({ children, config }) => {
|
|
|
783
794
|
setLoading(false);
|
|
784
795
|
}
|
|
785
796
|
}, [authService]);
|
|
786
|
-
const updateProfile =
|
|
797
|
+
const updateProfile = React.useCallback(async (data) => {
|
|
787
798
|
setLoading(true);
|
|
788
799
|
try {
|
|
789
800
|
const response = await authService.updateProfile(data);
|
|
@@ -795,7 +806,7 @@ var AuthProvider = ({ children, config }) => {
|
|
|
795
806
|
setLoading(false);
|
|
796
807
|
}
|
|
797
808
|
}, [authService]);
|
|
798
|
-
const getProfile =
|
|
809
|
+
const getProfile = React.useCallback(async () => {
|
|
799
810
|
setLoading(true);
|
|
800
811
|
try {
|
|
801
812
|
const userData = await authService.getProfile();
|
|
@@ -805,13 +816,13 @@ var AuthProvider = ({ children, config }) => {
|
|
|
805
816
|
setLoading(false);
|
|
806
817
|
}
|
|
807
818
|
}, [authService]);
|
|
808
|
-
const signInWithOAuth =
|
|
819
|
+
const signInWithOAuth = React.useCallback((provider) => {
|
|
809
820
|
authService.loginWithOAuth(provider);
|
|
810
821
|
}, [authService]);
|
|
811
|
-
const linkOAuthProvider =
|
|
822
|
+
const linkOAuthProvider = React.useCallback((provider) => {
|
|
812
823
|
authService.linkOAuthProvider(provider);
|
|
813
824
|
}, [authService]);
|
|
814
|
-
const unlinkOAuthProvider =
|
|
825
|
+
const unlinkOAuthProvider = React.useCallback(async (provider) => {
|
|
815
826
|
setLoading(true);
|
|
816
827
|
try {
|
|
817
828
|
return await authService.unlinkOAuthProvider(provider);
|
|
@@ -819,7 +830,7 @@ var AuthProvider = ({ children, config }) => {
|
|
|
819
830
|
setLoading(false);
|
|
820
831
|
}
|
|
821
832
|
}, [authService]);
|
|
822
|
-
const forgotPassword =
|
|
833
|
+
const forgotPassword = React.useCallback(async (email) => {
|
|
823
834
|
setLoading(true);
|
|
824
835
|
try {
|
|
825
836
|
return await authService.forgotPassword(email);
|
|
@@ -827,7 +838,7 @@ var AuthProvider = ({ children, config }) => {
|
|
|
827
838
|
setLoading(false);
|
|
828
839
|
}
|
|
829
840
|
}, [authService]);
|
|
830
|
-
const resetPassword =
|
|
841
|
+
const resetPassword = React.useCallback(async (token, password) => {
|
|
831
842
|
setLoading(true);
|
|
832
843
|
try {
|
|
833
844
|
return await authService.resetPassword(token, password);
|
|
@@ -835,7 +846,7 @@ var AuthProvider = ({ children, config }) => {
|
|
|
835
846
|
setLoading(false);
|
|
836
847
|
}
|
|
837
848
|
}, [authService]);
|
|
838
|
-
const changePassword =
|
|
849
|
+
const changePassword = React.useCallback(async (oldPassword, newPassword) => {
|
|
839
850
|
setLoading(true);
|
|
840
851
|
try {
|
|
841
852
|
return await authService.changePassword(oldPassword, newPassword);
|
|
@@ -843,7 +854,7 @@ var AuthProvider = ({ children, config }) => {
|
|
|
843
854
|
setLoading(false);
|
|
844
855
|
}
|
|
845
856
|
}, [authService]);
|
|
846
|
-
const updateAvatar =
|
|
857
|
+
const updateAvatar = React.useCallback(async (avatar) => {
|
|
847
858
|
setLoading(true);
|
|
848
859
|
try {
|
|
849
860
|
const response = await authService.updateAvatar(avatar);
|
|
@@ -855,7 +866,7 @@ var AuthProvider = ({ children, config }) => {
|
|
|
855
866
|
setLoading(false);
|
|
856
867
|
}
|
|
857
868
|
}, [authService]);
|
|
858
|
-
const uploadAndUpdateAvatar =
|
|
869
|
+
const uploadAndUpdateAvatar = React.useCallback(async (file) => {
|
|
859
870
|
setLoading(true);
|
|
860
871
|
try {
|
|
861
872
|
const response = await authService.uploadAndUpdateAvatar(file);
|
|
@@ -867,7 +878,7 @@ var AuthProvider = ({ children, config }) => {
|
|
|
867
878
|
setLoading(false);
|
|
868
879
|
}
|
|
869
880
|
}, [authService]);
|
|
870
|
-
const requestEmailChange =
|
|
881
|
+
const requestEmailChange = React.useCallback(async (newEmail) => {
|
|
871
882
|
setLoading(true);
|
|
872
883
|
try {
|
|
873
884
|
return await authService.requestEmailChange(newEmail);
|
|
@@ -875,7 +886,7 @@ var AuthProvider = ({ children, config }) => {
|
|
|
875
886
|
setLoading(false);
|
|
876
887
|
}
|
|
877
888
|
}, [authService]);
|
|
878
|
-
const verifyEmailChange =
|
|
889
|
+
const verifyEmailChange = React.useCallback(async (token) => {
|
|
879
890
|
setLoading(true);
|
|
880
891
|
try {
|
|
881
892
|
const response = await authService.verifyEmailChange(token);
|
|
@@ -887,7 +898,7 @@ var AuthProvider = ({ children, config }) => {
|
|
|
887
898
|
setLoading(false);
|
|
888
899
|
}
|
|
889
900
|
}, [authService]);
|
|
890
|
-
const generate2FA =
|
|
901
|
+
const generate2FA = React.useCallback(async () => {
|
|
891
902
|
setLoading(true);
|
|
892
903
|
try {
|
|
893
904
|
return await authService.generate2FA();
|
|
@@ -895,7 +906,7 @@ var AuthProvider = ({ children, config }) => {
|
|
|
895
906
|
setLoading(false);
|
|
896
907
|
}
|
|
897
908
|
}, [authService]);
|
|
898
|
-
const enable2FA =
|
|
909
|
+
const enable2FA = React.useCallback(async (token) => {
|
|
899
910
|
setLoading(true);
|
|
900
911
|
try {
|
|
901
912
|
return await authService.enable2FA(token);
|
|
@@ -903,7 +914,7 @@ var AuthProvider = ({ children, config }) => {
|
|
|
903
914
|
setLoading(false);
|
|
904
915
|
}
|
|
905
916
|
}, [authService]);
|
|
906
|
-
const disable2FA =
|
|
917
|
+
const disable2FA = React.useCallback(async (token) => {
|
|
907
918
|
setLoading(true);
|
|
908
919
|
try {
|
|
909
920
|
return await authService.disable2FA(token);
|
|
@@ -911,7 +922,7 @@ var AuthProvider = ({ children, config }) => {
|
|
|
911
922
|
setLoading(false);
|
|
912
923
|
}
|
|
913
924
|
}, [authService]);
|
|
914
|
-
const validate2FA =
|
|
925
|
+
const validate2FA = React.useCallback(async (token) => {
|
|
915
926
|
setLoading(true);
|
|
916
927
|
try {
|
|
917
928
|
return await authService.validate2FA(token);
|
|
@@ -919,7 +930,7 @@ var AuthProvider = ({ children, config }) => {
|
|
|
919
930
|
setLoading(false);
|
|
920
931
|
}
|
|
921
932
|
}, [authService]);
|
|
922
|
-
const getSessions =
|
|
933
|
+
const getSessions = React.useCallback(async () => {
|
|
923
934
|
setLoading(true);
|
|
924
935
|
try {
|
|
925
936
|
return await authService.getSessions();
|
|
@@ -927,7 +938,7 @@ var AuthProvider = ({ children, config }) => {
|
|
|
927
938
|
setLoading(false);
|
|
928
939
|
}
|
|
929
940
|
}, [authService]);
|
|
930
|
-
const revokeSession =
|
|
941
|
+
const revokeSession = React.useCallback(async (sessionId) => {
|
|
931
942
|
setLoading(true);
|
|
932
943
|
try {
|
|
933
944
|
return await authService.revokeSession(sessionId);
|
|
@@ -935,7 +946,7 @@ var AuthProvider = ({ children, config }) => {
|
|
|
935
946
|
setLoading(false);
|
|
936
947
|
}
|
|
937
948
|
}, [authService]);
|
|
938
|
-
const revokeAllSessions =
|
|
949
|
+
const revokeAllSessions = React.useCallback(async () => {
|
|
939
950
|
setLoading(true);
|
|
940
951
|
try {
|
|
941
952
|
const response = await authService.revokeAllSessions();
|
|
@@ -979,7 +990,7 @@ var AuthProvider = ({ children, config }) => {
|
|
|
979
990
|
return /* @__PURE__ */ jsxRuntime.jsx(AuthContext.Provider, { value, children: /* @__PURE__ */ jsxRuntime.jsx(AuthThemeProvider, { children }) });
|
|
980
991
|
};
|
|
981
992
|
var useAuth2 = () => {
|
|
982
|
-
const context =
|
|
993
|
+
const context = React.useContext(AuthContext);
|
|
983
994
|
if (context === void 0) {
|
|
984
995
|
throw new Error("useAuth must be used within an AuthProvider");
|
|
985
996
|
}
|
|
@@ -1035,7 +1046,7 @@ try {
|
|
|
1035
1046
|
} catch (error) {
|
|
1036
1047
|
console.warn("react-phone-number-input not available, using fallback");
|
|
1037
1048
|
}
|
|
1038
|
-
var CustomPhoneInput =
|
|
1049
|
+
var CustomPhoneInput = React__default.default.forwardRef((props, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1039
1050
|
"input",
|
|
1040
1051
|
{
|
|
1041
1052
|
...props,
|
|
@@ -1054,8 +1065,8 @@ var PhoneInput = ({
|
|
|
1054
1065
|
style = {}
|
|
1055
1066
|
}) => {
|
|
1056
1067
|
const colors = useThemeColors();
|
|
1057
|
-
const [defaultCountry, setDefaultCountry] =
|
|
1058
|
-
const styleContent =
|
|
1068
|
+
const [defaultCountry, setDefaultCountry] = React.useState("US");
|
|
1069
|
+
const styleContent = React.useMemo(() => `
|
|
1059
1070
|
.PhoneInput {
|
|
1060
1071
|
display: flex;
|
|
1061
1072
|
align-items: center;
|
|
@@ -1167,7 +1178,7 @@ var PhoneInput = ({
|
|
|
1167
1178
|
opacity: 0.6;
|
|
1168
1179
|
}
|
|
1169
1180
|
`, [colors]);
|
|
1170
|
-
|
|
1181
|
+
React.useEffect(() => {
|
|
1171
1182
|
const detectCountry = async () => {
|
|
1172
1183
|
try {
|
|
1173
1184
|
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
@@ -1224,7 +1235,7 @@ var PhoneInput = ({
|
|
|
1224
1235
|
};
|
|
1225
1236
|
detectCountry();
|
|
1226
1237
|
}, []);
|
|
1227
|
-
const handleChange =
|
|
1238
|
+
const handleChange = React.useMemo(() => (val) => {
|
|
1228
1239
|
onChange(val || "");
|
|
1229
1240
|
}, [onChange]);
|
|
1230
1241
|
if (!PhoneInputWithCountry) {
|
|
@@ -1288,15 +1299,15 @@ var LoginForm = ({
|
|
|
1288
1299
|
showOAuthButtons = true
|
|
1289
1300
|
}) => {
|
|
1290
1301
|
const colors = useThemeColors();
|
|
1291
|
-
const [email, setEmail] =
|
|
1292
|
-
const [phoneNumber, setPhoneNumber] =
|
|
1293
|
-
const [usePhone, setUsePhone] =
|
|
1294
|
-
const [password, setPassword] =
|
|
1295
|
-
const [usePassword, setUsePassword] =
|
|
1296
|
-
const [showPassword, setShowPassword] =
|
|
1297
|
-
const [isLoading, setIsLoading] =
|
|
1298
|
-
const [error, setError] =
|
|
1299
|
-
const [rememberMe, setRememberMe] =
|
|
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);
|
|
1300
1311
|
const { login } = useAuth({
|
|
1301
1312
|
baseUrl: config?.baseUrl || "http://localhost:7000"
|
|
1302
1313
|
});
|
|
@@ -1750,15 +1761,15 @@ var RegisterForm = ({
|
|
|
1750
1761
|
invitationToken
|
|
1751
1762
|
}) => {
|
|
1752
1763
|
const colors = useThemeColors();
|
|
1753
|
-
const [name, setName] =
|
|
1754
|
-
const [email, setEmail] =
|
|
1755
|
-
const [phoneNumber, setPhoneNumber] =
|
|
1756
|
-
const [password, setPassword] =
|
|
1757
|
-
const [confirmPassword, setConfirmPassword] =
|
|
1758
|
-
const [isLoading, setIsLoading] =
|
|
1759
|
-
const [error, setError] =
|
|
1760
|
-
const [showPassword, setShowPassword] =
|
|
1761
|
-
const [showConfirmPassword, setShowConfirmPassword] =
|
|
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);
|
|
1762
1773
|
const getPasswordStrength = (pwd) => {
|
|
1763
1774
|
if (!pwd) return { strength: "weak", score: 0, label: "" };
|
|
1764
1775
|
let score = 0;
|
|
@@ -2214,11 +2225,11 @@ var OtpForm = ({
|
|
|
2214
2225
|
baseUrl
|
|
2215
2226
|
}) => {
|
|
2216
2227
|
const colors = useThemeColors();
|
|
2217
|
-
const [otp, setOtp] =
|
|
2218
|
-
const [isLoading, setIsLoading] =
|
|
2219
|
-
const [error, setError] =
|
|
2220
|
-
const [resendCooldown, setResendCooldown] =
|
|
2221
|
-
const [resendLoading, setResendLoading] =
|
|
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);
|
|
2222
2233
|
const { verify, login } = useAuth({
|
|
2223
2234
|
baseUrl: baseUrl || process.env.NEXT_PUBLIC_AUTH_API_URL || "http://localhost:7000"
|
|
2224
2235
|
});
|
|
@@ -2429,9 +2440,9 @@ var AuthFlow = ({
|
|
|
2429
2440
|
initialStep = "login",
|
|
2430
2441
|
showTitle = true
|
|
2431
2442
|
}) => {
|
|
2432
|
-
const [step, setStep] =
|
|
2433
|
-
const [email, setEmail] =
|
|
2434
|
-
const [message, setMessage] =
|
|
2443
|
+
const [step, setStep] = React.useState(initialStep);
|
|
2444
|
+
const [email, setEmail] = React.useState("");
|
|
2445
|
+
const [message, setMessage] = React.useState(null);
|
|
2435
2446
|
const handleLoginSuccess = (email2, needsOtpVerification) => {
|
|
2436
2447
|
setEmail(email2);
|
|
2437
2448
|
if (needsOtpVerification) {
|
|
@@ -2566,13 +2577,13 @@ var EmailVerificationPage = ({
|
|
|
2566
2577
|
onVerificationError,
|
|
2567
2578
|
baseUrl
|
|
2568
2579
|
}) => {
|
|
2569
|
-
const [isLoading, setIsLoading] =
|
|
2570
|
-
const [message, setMessage] =
|
|
2571
|
-
const [isSuccess, setIsSuccess] =
|
|
2580
|
+
const [isLoading, setIsLoading] = React.useState(true);
|
|
2581
|
+
const [message, setMessage] = React.useState("");
|
|
2582
|
+
const [isSuccess, setIsSuccess] = React.useState(false);
|
|
2572
2583
|
const { verifyEmailToken } = useAuth({
|
|
2573
2584
|
baseUrl: baseUrl || (typeof window !== "undefined" ? window.location.origin : "http://localhost:7000")
|
|
2574
2585
|
});
|
|
2575
|
-
|
|
2586
|
+
React.useEffect(() => {
|
|
2576
2587
|
const verifyEmail = async () => {
|
|
2577
2588
|
if (!token) {
|
|
2578
2589
|
setIsLoading(false);
|
|
@@ -2677,7 +2688,7 @@ var EmailVerificationPage = ({
|
|
|
2677
2688
|
] })
|
|
2678
2689
|
] }) });
|
|
2679
2690
|
};
|
|
2680
|
-
var ThemeWrapper =
|
|
2691
|
+
var ThemeWrapper = React.forwardRef(
|
|
2681
2692
|
({ children, className = "", style }, ref) => {
|
|
2682
2693
|
const { theme, mounted } = useAuthTheme();
|
|
2683
2694
|
if (!mounted) {
|
|
@@ -2690,18 +2701,18 @@ ThemeWrapper.displayName = "ThemeWrapper";
|
|
|
2690
2701
|
var SignIn = ({ redirectUrl, appearance }) => {
|
|
2691
2702
|
const { signIn, isSignedIn, loading: authLoading } = useAuth2();
|
|
2692
2703
|
const colors = useThemeColors();
|
|
2693
|
-
const [email, setEmail] =
|
|
2694
|
-
const [phoneNumber, setPhoneNumber] =
|
|
2695
|
-
const [password, setPassword] =
|
|
2696
|
-
const [otp, setOtp] =
|
|
2697
|
-
const [usePassword, setUsePassword] =
|
|
2698
|
-
const [usePhone, setUsePhone] =
|
|
2699
|
-
const [showPassword, setShowPassword] =
|
|
2700
|
-
const [isLoading, setIsLoading] =
|
|
2701
|
-
const [error, setError] =
|
|
2702
|
-
const [needsOtp, setNeedsOtp] =
|
|
2703
|
-
const [success, setSuccess] =
|
|
2704
|
-
|
|
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(() => {
|
|
2705
2716
|
if (isSignedIn && redirectUrl) {
|
|
2706
2717
|
const redirect = redirectUrl || process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_AFTER_LOGIN || "/dashboard";
|
|
2707
2718
|
const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
|
|
@@ -3092,16 +3103,16 @@ var SignIn = ({ redirectUrl, appearance }) => {
|
|
|
3092
3103
|
var SignUp = ({ redirectUrl, appearance }) => {
|
|
3093
3104
|
const { signUp, isSignedIn } = useAuth2();
|
|
3094
3105
|
const colors = useThemeColors();
|
|
3095
|
-
const [name, setName] =
|
|
3096
|
-
const [email, setEmail] =
|
|
3097
|
-
const [phoneNumber, setPhoneNumber] =
|
|
3098
|
-
const [password, setPassword] =
|
|
3099
|
-
const [confirmPassword, setConfirmPassword] =
|
|
3100
|
-
const [showPassword, setShowPassword] =
|
|
3101
|
-
const [isLoading, setIsLoading] =
|
|
3102
|
-
const [error, setError] =
|
|
3103
|
-
const [success, setSuccess] =
|
|
3104
|
-
|
|
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(() => {
|
|
3105
3116
|
if (isSignedIn && redirectUrl) {
|
|
3106
3117
|
const redirect = redirectUrl || process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_REGISTER || process.env.REACT_APP_AUTH_REDIRECT_AFTER_REGISTER || "/dashboard";
|
|
3107
3118
|
const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
|
|
@@ -3455,7 +3466,7 @@ var SignUp = ({ redirectUrl, appearance }) => {
|
|
|
3455
3466
|
};
|
|
3456
3467
|
var SignOut = ({ redirectUrl }) => {
|
|
3457
3468
|
const { signOut } = useAuth2();
|
|
3458
|
-
|
|
3469
|
+
React.useEffect(() => {
|
|
3459
3470
|
const performSignOut = async () => {
|
|
3460
3471
|
await signOut();
|
|
3461
3472
|
const redirect = redirectUrl || process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_LOGOUT || process.env.REACT_APP_AUTH_REDIRECT_AFTER_LOGOUT || "/";
|
|
@@ -3469,9 +3480,9 @@ var SignOut = ({ redirectUrl }) => {
|
|
|
3469
3480
|
var UserButton = ({ showName = false, appearance }) => {
|
|
3470
3481
|
const { user, signOut } = useAuth2();
|
|
3471
3482
|
const colors = useThemeColors();
|
|
3472
|
-
const [isOpen, setIsOpen] =
|
|
3473
|
-
const dropdownRef =
|
|
3474
|
-
|
|
3483
|
+
const [isOpen, setIsOpen] = React.useState(false);
|
|
3484
|
+
const dropdownRef = React.useRef(null);
|
|
3485
|
+
React.useEffect(() => {
|
|
3475
3486
|
const handleClickOutside = (event) => {
|
|
3476
3487
|
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
|
3477
3488
|
setIsOpen(false);
|
|
@@ -3514,7 +3525,19 @@ var UserButton = ({ showName = false, appearance }) => {
|
|
|
3514
3525
|
e.currentTarget.style.backgroundColor = "transparent";
|
|
3515
3526
|
},
|
|
3516
3527
|
children: [
|
|
3517
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
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: {
|
|
3518
3541
|
width: "36px",
|
|
3519
3542
|
height: "36px",
|
|
3520
3543
|
borderRadius: "50%",
|
|
@@ -3551,7 +3574,19 @@ var UserButton = ({ showName = false, appearance }) => {
|
|
|
3551
3574
|
alignItems: "center",
|
|
3552
3575
|
gap: "12px"
|
|
3553
3576
|
}, children: [
|
|
3554
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
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: {
|
|
3555
3590
|
width: "48px",
|
|
3556
3591
|
height: "48px",
|
|
3557
3592
|
borderRadius: "50%",
|
|
@@ -3616,7 +3651,7 @@ var ProtectedRoute = ({
|
|
|
3616
3651
|
redirectTo
|
|
3617
3652
|
}) => {
|
|
3618
3653
|
const { isSignedIn, isLoaded } = useAuth2();
|
|
3619
|
-
|
|
3654
|
+
React.useEffect(() => {
|
|
3620
3655
|
if (isLoaded && !isSignedIn) {
|
|
3621
3656
|
const loginPath = redirectTo || process.env.NEXT_PUBLIC_AUTH_REDIRECT_TO_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_TO_LOGIN || "/auth/login";
|
|
3622
3657
|
const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
|
|
@@ -3641,7 +3676,7 @@ var PublicRoute = ({
|
|
|
3641
3676
|
redirectTo
|
|
3642
3677
|
}) => {
|
|
3643
3678
|
const { isSignedIn, isLoaded } = useAuth2();
|
|
3644
|
-
|
|
3679
|
+
React.useEffect(() => {
|
|
3645
3680
|
if (isLoaded && isSignedIn) {
|
|
3646
3681
|
const dashboardPath = redirectTo || process.env.NEXT_PUBLIC_AUTH_REDIRECT_AFTER_LOGIN || process.env.REACT_APP_AUTH_REDIRECT_AFTER_LOGIN || "/dashboard";
|
|
3647
3682
|
const baseUrl = process.env.NEXT_PUBLIC_FRONTEND_BASE_URL || process.env.REACT_APP_FRONTEND_BASE_URL || (typeof window !== "undefined" ? window.location.origin : "");
|
|
@@ -3663,9 +3698,9 @@ var PublicRoute = ({
|
|
|
3663
3698
|
};
|
|
3664
3699
|
var VerifyEmail = ({ token, onSuccess, onError }) => {
|
|
3665
3700
|
const { verifyEmailToken } = useAuth2();
|
|
3666
|
-
const [status, setStatus] =
|
|
3667
|
-
const [message, setMessage] =
|
|
3668
|
-
|
|
3701
|
+
const [status, setStatus] = React.useState("loading");
|
|
3702
|
+
const [message, setMessage] = React.useState("");
|
|
3703
|
+
React.useEffect(() => {
|
|
3669
3704
|
const verify = async () => {
|
|
3670
3705
|
const verifyToken = token || (typeof window !== "undefined" ? new URLSearchParams(window.location.search).get("token") : null);
|
|
3671
3706
|
if (!verifyToken) {
|
|
@@ -3799,10 +3834,10 @@ var VerifyEmail = ({ token, onSuccess, onError }) => {
|
|
|
3799
3834
|
};
|
|
3800
3835
|
var ForgotPassword = ({ appearance }) => {
|
|
3801
3836
|
const { forgotPassword } = useAuth2();
|
|
3802
|
-
const [email, setEmail] =
|
|
3803
|
-
const [isLoading, setIsLoading] =
|
|
3804
|
-
const [error, setError] =
|
|
3805
|
-
const [success, setSuccess] =
|
|
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);
|
|
3806
3841
|
const handleSubmit = async (e) => {
|
|
3807
3842
|
e.preventDefault();
|
|
3808
3843
|
setIsLoading(true);
|
|
@@ -3941,14 +3976,14 @@ var ForgotPassword = ({ appearance }) => {
|
|
|
3941
3976
|
};
|
|
3942
3977
|
var ResetPassword = ({ token, appearance }) => {
|
|
3943
3978
|
const { resetPassword } = useAuth2();
|
|
3944
|
-
const [resetToken, setResetToken] =
|
|
3945
|
-
const [password, setPassword] =
|
|
3946
|
-
const [confirmPassword, setConfirmPassword] =
|
|
3947
|
-
const [showPassword, setShowPassword] =
|
|
3948
|
-
const [isLoading, setIsLoading] =
|
|
3949
|
-
const [error, setError] =
|
|
3950
|
-
const [success, setSuccess] =
|
|
3951
|
-
|
|
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(() => {
|
|
3952
3987
|
if (!resetToken && typeof window !== "undefined") {
|
|
3953
3988
|
const urlToken = new URLSearchParams(window.location.search).get("token");
|
|
3954
3989
|
if (urlToken) {
|
|
@@ -4195,13 +4230,13 @@ var ResetPassword = ({ token, appearance }) => {
|
|
|
4195
4230
|
};
|
|
4196
4231
|
var ChangePassword = ({ onSuccess, appearance }) => {
|
|
4197
4232
|
const { changePassword } = useAuth2();
|
|
4198
|
-
const [oldPassword, setOldPassword] =
|
|
4199
|
-
const [newPassword, setNewPassword] =
|
|
4200
|
-
const [confirmPassword, setConfirmPassword] =
|
|
4201
|
-
const [showPasswords, setShowPasswords] =
|
|
4202
|
-
const [isLoading, setIsLoading] =
|
|
4203
|
-
const [error, setError] =
|
|
4204
|
-
const [success, setSuccess] =
|
|
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);
|
|
4205
4240
|
const getPasswordStrength = (pwd) => {
|
|
4206
4241
|
if (!pwd) return { strength: "weak", color: "#ddd" };
|
|
4207
4242
|
let score = 0;
|
|
@@ -4431,6 +4466,68 @@ var ChangePassword = ({ onSuccess, appearance }) => {
|
|
|
4431
4466
|
)
|
|
4432
4467
|
] }) });
|
|
4433
4468
|
};
|
|
4469
|
+
|
|
4470
|
+
// src/react/components/utils/injectModalStyles.ts
|
|
4471
|
+
var injectModalStyles = () => {
|
|
4472
|
+
if (document.getElementById("ttf-auth-modal-styles")) {
|
|
4473
|
+
return;
|
|
4474
|
+
}
|
|
4475
|
+
const styleElement = document.createElement("style");
|
|
4476
|
+
styleElement.id = "ttf-auth-modal-styles";
|
|
4477
|
+
styleElement.textContent = `
|
|
4478
|
+
/* ImageManager Modal Styles - Critical for proper modal display */
|
|
4479
|
+
/* Radix UI Dialog styles - Force visibility */
|
|
4480
|
+
[data-radix-portal] {
|
|
4481
|
+
z-index: 99999 !important;
|
|
4482
|
+
position: fixed !important;
|
|
4483
|
+
inset: 0 !important;
|
|
4484
|
+
pointer-events: none !important;
|
|
4485
|
+
}
|
|
4486
|
+
|
|
4487
|
+
[data-radix-portal] > * {
|
|
4488
|
+
pointer-events: auto !important;
|
|
4489
|
+
}
|
|
4490
|
+
|
|
4491
|
+
/* Dialog Overlay */
|
|
4492
|
+
[data-state="open"][data-radix-dialog-overlay],
|
|
4493
|
+
[role="dialog"] + [data-radix-dialog-overlay] {
|
|
4494
|
+
position: fixed !important;
|
|
4495
|
+
inset: 0 !important;
|
|
4496
|
+
z-index: 99998 !important;
|
|
4497
|
+
background-color: rgba(0, 0, 0, 0.6) !important;
|
|
4498
|
+
pointer-events: auto !important;
|
|
4499
|
+
}
|
|
4500
|
+
|
|
4501
|
+
/* Dialog Content - Center the modal properly */
|
|
4502
|
+
[data-state="open"][data-radix-dialog-content],
|
|
4503
|
+
[role="dialog"][data-radix-dialog-content] {
|
|
4504
|
+
position: fixed !important;
|
|
4505
|
+
left: 50% !important;
|
|
4506
|
+
top: 50% !important;
|
|
4507
|
+
transform: translate(-50%, -50%) !important;
|
|
4508
|
+
z-index: 99999 !important;
|
|
4509
|
+
background: white !important;
|
|
4510
|
+
border-radius: 16px !important;
|
|
4511
|
+
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25) !important;
|
|
4512
|
+
pointer-events: auto !important;
|
|
4513
|
+
width: 95vw !important;
|
|
4514
|
+
max-width: 1280px !important;
|
|
4515
|
+
height: 90vh !important;
|
|
4516
|
+
max-height: 90vh !important;
|
|
4517
|
+
min-width: 800px !important;
|
|
4518
|
+
min-height: 600px !important;
|
|
4519
|
+
overflow: hidden !important;
|
|
4520
|
+
}
|
|
4521
|
+
|
|
4522
|
+
/* Dark mode support */
|
|
4523
|
+
.dark [data-state="open"][data-radix-dialog-content],
|
|
4524
|
+
.dark [role="dialog"][data-radix-dialog-content] {
|
|
4525
|
+
background: #0f172a !important;
|
|
4526
|
+
border: 1px solid #334155 !important;
|
|
4527
|
+
}
|
|
4528
|
+
`;
|
|
4529
|
+
document.head.appendChild(styleElement);
|
|
4530
|
+
};
|
|
4434
4531
|
var AvatarUploader = ({
|
|
4435
4532
|
onUploadComplete,
|
|
4436
4533
|
onError,
|
|
@@ -4441,32 +4538,30 @@ var AvatarUploader = ({
|
|
|
4441
4538
|
upfilesConfig,
|
|
4442
4539
|
buttonText = "Upload Avatar"
|
|
4443
4540
|
}) => {
|
|
4444
|
-
const {
|
|
4445
|
-
const [open, setOpen] =
|
|
4446
|
-
const [uploading, setUploading] =
|
|
4541
|
+
const { user, updateProfile } = useAuth2();
|
|
4542
|
+
const [open, setOpen] = React.useState(false);
|
|
4543
|
+
const [uploading, setUploading] = React.useState(false);
|
|
4544
|
+
React.useEffect(() => {
|
|
4545
|
+
injectModalStyles();
|
|
4546
|
+
}, []);
|
|
4547
|
+
const effectiveFolderPath = React.useMemo(() => {
|
|
4548
|
+
if (user?.id) {
|
|
4549
|
+
return `users/${user.id}/`;
|
|
4550
|
+
}
|
|
4551
|
+
return upfilesConfig.folderPath || "/";
|
|
4552
|
+
}, [user?.id, upfilesConfig.folderPath]);
|
|
4447
4553
|
const handleSelect = async (image) => {
|
|
4448
4554
|
setUploading(true);
|
|
4449
4555
|
try {
|
|
4450
|
-
const
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
[upfilesConfig.apiKeyHeader || "authorization"]: upfilesConfig.apiKey.startsWith("upk_") ? `Bearer ${upfilesConfig.apiKey}` : upfilesConfig.apiKey
|
|
4454
|
-
} : {}
|
|
4455
|
-
});
|
|
4456
|
-
if (!response.ok) {
|
|
4457
|
-
throw new Error("Failed to fetch image");
|
|
4458
|
-
}
|
|
4459
|
-
const blob = await response.blob();
|
|
4460
|
-
const file = new File([blob], image.originalName, { type: image.contentType });
|
|
4461
|
-
const result = await uploadAndUpdateAvatar(file);
|
|
4462
|
-
if (result.success && result.user?.avatar) {
|
|
4463
|
-
onUploadComplete?.(result.user.avatar);
|
|
4556
|
+
const response = await updateProfile({ avatar: image.url });
|
|
4557
|
+
if (response.success && response.user?.avatar) {
|
|
4558
|
+
onUploadComplete?.(response.user.avatar);
|
|
4464
4559
|
setOpen(false);
|
|
4465
4560
|
} else {
|
|
4466
|
-
throw new Error(
|
|
4561
|
+
throw new Error(response.message || "Failed to update avatar");
|
|
4467
4562
|
}
|
|
4468
4563
|
} catch (error) {
|
|
4469
|
-
const err = error instanceof Error ? error : new Error("
|
|
4564
|
+
const err = error instanceof Error ? error : new Error("Failed to update avatar");
|
|
4470
4565
|
onError?.(err);
|
|
4471
4566
|
} finally {
|
|
4472
4567
|
setUploading(false);
|
|
@@ -4496,7 +4591,7 @@ var AvatarUploader = ({
|
|
|
4496
4591
|
presignPath: upfilesConfig.presignPath
|
|
4497
4592
|
},
|
|
4498
4593
|
projectId: upfilesConfig.projectId,
|
|
4499
|
-
folderPath:
|
|
4594
|
+
folderPath: effectiveFolderPath,
|
|
4500
4595
|
title: "Select Avatar",
|
|
4501
4596
|
description: "Upload a new avatar or select from existing images.",
|
|
4502
4597
|
mode: "full",
|
|
@@ -4517,12 +4612,12 @@ var UserProfile = ({
|
|
|
4517
4612
|
}) => {
|
|
4518
4613
|
const { user, updateProfile, requestEmailChange } = useAuth2();
|
|
4519
4614
|
const colors = useThemeColors();
|
|
4520
|
-
const [name, setName] =
|
|
4521
|
-
const [phoneNumber, setPhoneNumber] =
|
|
4522
|
-
const [newEmail, setNewEmail] =
|
|
4523
|
-
const [isLoading, setIsLoading] =
|
|
4524
|
-
const [error, setError] =
|
|
4525
|
-
const [success, setSuccess] =
|
|
4615
|
+
const [name, setName] = React.useState(user?.name || "");
|
|
4616
|
+
const [phoneNumber, setPhoneNumber] = React.useState(user?.phoneNumber || "");
|
|
4617
|
+
const [newEmail, setNewEmail] = React.useState("");
|
|
4618
|
+
const [isLoading, setIsLoading] = React.useState(false);
|
|
4619
|
+
const [error, setError] = React.useState(null);
|
|
4620
|
+
const [success, setSuccess] = React.useState(null);
|
|
4526
4621
|
const handleUpdateProfile = async (e) => {
|
|
4527
4622
|
e.preventDefault();
|
|
4528
4623
|
setIsLoading(true);
|
|
@@ -4813,12 +4908,27 @@ var AvatarManager = ({
|
|
|
4813
4908
|
gridClassName,
|
|
4814
4909
|
maxFileSize = 5 * 1024 * 1024,
|
|
4815
4910
|
// 5MB default
|
|
4911
|
+
maxFiles = 10,
|
|
4816
4912
|
mode = "full",
|
|
4817
4913
|
showDelete = false,
|
|
4914
|
+
autoRecordToDb = true,
|
|
4915
|
+
fetchThumbnails = true,
|
|
4916
|
+
projectId,
|
|
4917
|
+
deleteUrl,
|
|
4918
|
+
onDelete,
|
|
4818
4919
|
upfilesConfig
|
|
4819
4920
|
}) => {
|
|
4820
|
-
const { updateProfile } = useAuth2();
|
|
4821
|
-
const [updating, setUpdating] =
|
|
4921
|
+
const { user, updateProfile } = useAuth2();
|
|
4922
|
+
const [updating, setUpdating] = React.useState(false);
|
|
4923
|
+
React.useEffect(() => {
|
|
4924
|
+
injectModalStyles();
|
|
4925
|
+
}, []);
|
|
4926
|
+
const effectiveFolderPath = React.useMemo(() => {
|
|
4927
|
+
if (user?.id) {
|
|
4928
|
+
return `users/${user.id}/`;
|
|
4929
|
+
}
|
|
4930
|
+
return upfilesConfig.folderPath || "/";
|
|
4931
|
+
}, [user?.id, upfilesConfig.folderPath]);
|
|
4822
4932
|
const handleSelect = async (image) => {
|
|
4823
4933
|
setUpdating(true);
|
|
4824
4934
|
try {
|
|
@@ -4846,24 +4956,31 @@ var AvatarManager = ({
|
|
|
4846
4956
|
apiKey: upfilesConfig.apiKey,
|
|
4847
4957
|
apiKeyHeader: upfilesConfig.apiKeyHeader || "authorization",
|
|
4848
4958
|
presignUrl: upfilesConfig.presignUrl,
|
|
4849
|
-
presignPath: upfilesConfig.presignPath
|
|
4959
|
+
presignPath: upfilesConfig.presignPath,
|
|
4960
|
+
headers: upfilesConfig.headers,
|
|
4961
|
+
withCredentials: upfilesConfig.withCredentials
|
|
4850
4962
|
},
|
|
4851
|
-
|
|
4963
|
+
projectId,
|
|
4964
|
+
folderPath: effectiveFolderPath,
|
|
4852
4965
|
title,
|
|
4853
4966
|
description,
|
|
4854
4967
|
className,
|
|
4855
4968
|
gridClassName,
|
|
4856
4969
|
onSelect: handleSelect,
|
|
4970
|
+
onDelete,
|
|
4971
|
+
deleteUrl,
|
|
4972
|
+
autoRecordToDb,
|
|
4973
|
+
fetchThumbnails,
|
|
4857
4974
|
maxFileSize,
|
|
4975
|
+
maxFiles,
|
|
4858
4976
|
mode,
|
|
4859
|
-
showDelete
|
|
4860
|
-
fetchThumbnails: true
|
|
4977
|
+
showDelete
|
|
4861
4978
|
}
|
|
4862
4979
|
);
|
|
4863
4980
|
};
|
|
4864
4981
|
var isServer = typeof window === "undefined";
|
|
4865
4982
|
var useNextAuth = (config) => {
|
|
4866
|
-
const [authService] =
|
|
4983
|
+
const [authService] = React.useState(() => {
|
|
4867
4984
|
const service = new AuthService(config);
|
|
4868
4985
|
if (isServer && config.token) {
|
|
4869
4986
|
service["token"] = config.token;
|
|
@@ -4871,10 +4988,10 @@ var useNextAuth = (config) => {
|
|
|
4871
4988
|
}
|
|
4872
4989
|
return service;
|
|
4873
4990
|
});
|
|
4874
|
-
const [user, setUser] =
|
|
4875
|
-
const [isAuthenticated, setIsAuthenticated] =
|
|
4876
|
-
const [loading, setLoading] =
|
|
4877
|
-
const checkAuthStatus =
|
|
4991
|
+
const [user, setUser] = React.useState(null);
|
|
4992
|
+
const [isAuthenticated, setIsAuthenticated] = React.useState(false);
|
|
4993
|
+
const [loading, setLoading] = React.useState(true);
|
|
4994
|
+
const checkAuthStatus = React.useCallback(() => {
|
|
4878
4995
|
if (isServer) {
|
|
4879
4996
|
const token = config.token || authService.getToken();
|
|
4880
4997
|
const authenticated = !!token;
|
|
@@ -4902,10 +5019,10 @@ var useNextAuth = (config) => {
|
|
|
4902
5019
|
}
|
|
4903
5020
|
setLoading(false);
|
|
4904
5021
|
}, [authService, config.token]);
|
|
4905
|
-
|
|
5022
|
+
React.useEffect(() => {
|
|
4906
5023
|
checkAuthStatus();
|
|
4907
5024
|
}, [checkAuthStatus]);
|
|
4908
|
-
const register =
|
|
5025
|
+
const register = React.useCallback(async (data) => {
|
|
4909
5026
|
setLoading(true);
|
|
4910
5027
|
try {
|
|
4911
5028
|
const response = await authService.register(data);
|
|
@@ -4914,7 +5031,7 @@ var useNextAuth = (config) => {
|
|
|
4914
5031
|
setLoading(false);
|
|
4915
5032
|
}
|
|
4916
5033
|
}, [authService]);
|
|
4917
|
-
const login =
|
|
5034
|
+
const login = React.useCallback(async (data) => {
|
|
4918
5035
|
setLoading(true);
|
|
4919
5036
|
try {
|
|
4920
5037
|
const response = await authService.login(data);
|
|
@@ -4923,7 +5040,7 @@ var useNextAuth = (config) => {
|
|
|
4923
5040
|
setLoading(false);
|
|
4924
5041
|
}
|
|
4925
5042
|
}, [authService]);
|
|
4926
|
-
const verify =
|
|
5043
|
+
const verify = React.useCallback(async (data) => {
|
|
4927
5044
|
setLoading(true);
|
|
4928
5045
|
try {
|
|
4929
5046
|
const response = await authService.verify(data);
|
|
@@ -4936,7 +5053,7 @@ var useNextAuth = (config) => {
|
|
|
4936
5053
|
setLoading(false);
|
|
4937
5054
|
}
|
|
4938
5055
|
}, [authService]);
|
|
4939
|
-
const verifyEmailToken =
|
|
5056
|
+
const verifyEmailToken = React.useCallback(async (token) => {
|
|
4940
5057
|
setLoading(true);
|
|
4941
5058
|
try {
|
|
4942
5059
|
const response = await authService.verifyEmailToken(token);
|
|
@@ -4949,7 +5066,7 @@ var useNextAuth = (config) => {
|
|
|
4949
5066
|
setLoading(false);
|
|
4950
5067
|
}
|
|
4951
5068
|
}, [authService]);
|
|
4952
|
-
const logout =
|
|
5069
|
+
const logout = React.useCallback(async () => {
|
|
4953
5070
|
setLoading(true);
|
|
4954
5071
|
try {
|
|
4955
5072
|
await authService.logout();
|
|
@@ -4959,7 +5076,7 @@ var useNextAuth = (config) => {
|
|
|
4959
5076
|
setLoading(false);
|
|
4960
5077
|
}
|
|
4961
5078
|
}, [authService]);
|
|
4962
|
-
const updateProfile =
|
|
5079
|
+
const updateProfile = React.useCallback(async (data) => {
|
|
4963
5080
|
setLoading(true);
|
|
4964
5081
|
try {
|
|
4965
5082
|
const response = await authService.updateProfile(data);
|
|
@@ -4971,7 +5088,7 @@ var useNextAuth = (config) => {
|
|
|
4971
5088
|
setLoading(false);
|
|
4972
5089
|
}
|
|
4973
5090
|
}, [authService]);
|
|
4974
|
-
const getProfile =
|
|
5091
|
+
const getProfile = React.useCallback(async () => {
|
|
4975
5092
|
setLoading(true);
|
|
4976
5093
|
try {
|
|
4977
5094
|
const userData = await authService.getProfile();
|
|
@@ -4981,7 +5098,7 @@ var useNextAuth = (config) => {
|
|
|
4981
5098
|
setLoading(false);
|
|
4982
5099
|
}
|
|
4983
5100
|
}, [authService]);
|
|
4984
|
-
const getAllUsers =
|
|
5101
|
+
const getAllUsers = React.useCallback(async () => {
|
|
4985
5102
|
setLoading(true);
|
|
4986
5103
|
try {
|
|
4987
5104
|
return await authService.getAllUsers();
|
|
@@ -4989,7 +5106,7 @@ var useNextAuth = (config) => {
|
|
|
4989
5106
|
setLoading(false);
|
|
4990
5107
|
}
|
|
4991
5108
|
}, [authService]);
|
|
4992
|
-
const getUserById =
|
|
5109
|
+
const getUserById = React.useCallback(async (id) => {
|
|
4993
5110
|
setLoading(true);
|
|
4994
5111
|
try {
|
|
4995
5112
|
return await authService.getUserById(id);
|
|
@@ -4997,7 +5114,7 @@ var useNextAuth = (config) => {
|
|
|
4997
5114
|
setLoading(false);
|
|
4998
5115
|
}
|
|
4999
5116
|
}, [authService]);
|
|
5000
|
-
const forgotPassword =
|
|
5117
|
+
const forgotPassword = React.useCallback(async (email) => {
|
|
5001
5118
|
setLoading(true);
|
|
5002
5119
|
try {
|
|
5003
5120
|
const response = await authService.forgotPassword(email);
|
|
@@ -5006,7 +5123,7 @@ var useNextAuth = (config) => {
|
|
|
5006
5123
|
setLoading(false);
|
|
5007
5124
|
}
|
|
5008
5125
|
}, [authService]);
|
|
5009
|
-
const resetPassword =
|
|
5126
|
+
const resetPassword = React.useCallback(async (token, password) => {
|
|
5010
5127
|
setLoading(true);
|
|
5011
5128
|
try {
|
|
5012
5129
|
const response = await authService.resetPassword(token, password);
|
|
@@ -5015,7 +5132,7 @@ var useNextAuth = (config) => {
|
|
|
5015
5132
|
setLoading(false);
|
|
5016
5133
|
}
|
|
5017
5134
|
}, [authService]);
|
|
5018
|
-
const setToken =
|
|
5135
|
+
const setToken = React.useCallback((token) => {
|
|
5019
5136
|
authService["token"] = token;
|
|
5020
5137
|
authService["httpClient"].setAuthToken(token);
|
|
5021
5138
|
setIsAuthenticated(true);
|
|
@@ -5027,7 +5144,7 @@ var useNextAuth = (config) => {
|
|
|
5027
5144
|
setUser(null);
|
|
5028
5145
|
}
|
|
5029
5146
|
}, [authService]);
|
|
5030
|
-
const clearToken =
|
|
5147
|
+
const clearToken = React.useCallback(() => {
|
|
5031
5148
|
authService["token"] = null;
|
|
5032
5149
|
authService["httpClient"].removeAuthToken();
|
|
5033
5150
|
setIsAuthenticated(false);
|