@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.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 __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 =
|
|
518
|
+
var ThemeContext = React__default.default.createContext({ theme: "light", mounted: false });
|
|
514
519
|
function AuthThemeProvider({ children }) {
|
|
515
|
-
const [theme, setTheme] =
|
|
516
|
-
const [mounted, setMounted] =
|
|
517
|
-
|
|
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
|
|
567
|
+
return React.useContext(ThemeContext);
|
|
563
568
|
}
|
|
564
|
-
var AuthContext =
|
|
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] =
|
|
573
|
-
const [user, setUser] =
|
|
574
|
-
const [isLoaded, setIsLoaded] =
|
|
575
|
-
const [loading, setLoading] =
|
|
576
|
-
const checkAuthStatus =
|
|
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
|
|
581
|
-
setUser(
|
|
585
|
+
const freshUser = await authService.getProfile();
|
|
586
|
+
setUser(freshUser);
|
|
582
587
|
} catch (error) {
|
|
583
|
-
console.error("Failed to
|
|
584
|
-
|
|
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
|
-
|
|
602
|
+
React.useEffect(() => {
|
|
592
603
|
checkAuthStatus();
|
|
593
604
|
}, [checkAuthStatus]);
|
|
594
|
-
const signIn =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
681
|
+
const signInWithOAuth = React.useCallback((provider) => {
|
|
671
682
|
authService.loginWithOAuth(provider);
|
|
672
683
|
}, [authService]);
|
|
673
|
-
const linkOAuthProvider =
|
|
684
|
+
const linkOAuthProvider = React.useCallback((provider) => {
|
|
674
685
|
authService.linkOAuthProvider(provider);
|
|
675
686
|
}, [authService]);
|
|
676
|
-
const unlinkOAuthProvider =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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] =
|
|
852
|
-
const [user, setUser] =
|
|
853
|
-
const [isAuthenticated, setIsAuthenticated] =
|
|
854
|
-
const [loading, setLoading] =
|
|
855
|
-
const checkAuthStatus =
|
|
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
|
-
|
|
877
|
+
React.useEffect(() => {
|
|
867
878
|
checkAuthStatus();
|
|
868
879
|
}, [checkAuthStatus]);
|
|
869
|
-
const register =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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] =
|
|
1063
|
-
const styleContent =
|
|
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
|
-
|
|
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 =
|
|
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] =
|
|
1297
|
-
const [phoneNumber, setPhoneNumber] =
|
|
1298
|
-
const [usePhone, setUsePhone] =
|
|
1299
|
-
const [password, setPassword] =
|
|
1300
|
-
const [usePassword, setUsePassword] =
|
|
1301
|
-
const [showPassword, setShowPassword] =
|
|
1302
|
-
const [isLoading, setIsLoading] =
|
|
1303
|
-
const [error, setError] =
|
|
1304
|
-
const [rememberMe, setRememberMe] =
|
|
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] =
|
|
1759
|
-
const [email, setEmail] =
|
|
1760
|
-
const [phoneNumber, setPhoneNumber] =
|
|
1761
|
-
const [password, setPassword] =
|
|
1762
|
-
const [confirmPassword, setConfirmPassword] =
|
|
1763
|
-
const [isLoading, setIsLoading] =
|
|
1764
|
-
const [error, setError] =
|
|
1765
|
-
const [showPassword, setShowPassword] =
|
|
1766
|
-
const [showConfirmPassword, setShowConfirmPassword] =
|
|
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] =
|
|
2223
|
-
const [isLoading, setIsLoading] =
|
|
2224
|
-
const [error, setError] =
|
|
2225
|
-
const [resendCooldown, setResendCooldown] =
|
|
2226
|
-
const [resendLoading, setResendLoading] =
|
|
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] =
|
|
2438
|
-
const [email, setEmail] =
|
|
2439
|
-
const [message, setMessage] =
|
|
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] =
|
|
2575
|
-
const [message, setMessage] =
|
|
2576
|
-
const [isSuccess, setIsSuccess] =
|
|
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
|
-
|
|
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 =
|
|
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] =
|
|
2699
|
-
const [phoneNumber, setPhoneNumber] =
|
|
2700
|
-
const [password, setPassword] =
|
|
2701
|
-
const [otp, setOtp] =
|
|
2702
|
-
const [usePassword, setUsePassword] =
|
|
2703
|
-
const [usePhone, setUsePhone] =
|
|
2704
|
-
const [showPassword, setShowPassword] =
|
|
2705
|
-
const [isLoading, setIsLoading] =
|
|
2706
|
-
const [error, setError] =
|
|
2707
|
-
const [needsOtp, setNeedsOtp] =
|
|
2708
|
-
const [success, setSuccess] =
|
|
2709
|
-
|
|
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] =
|
|
3101
|
-
const [email, setEmail] =
|
|
3102
|
-
const [phoneNumber, setPhoneNumber] =
|
|
3103
|
-
const [password, setPassword] =
|
|
3104
|
-
const [confirmPassword, setConfirmPassword] =
|
|
3105
|
-
const [showPassword, setShowPassword] =
|
|
3106
|
-
const [isLoading, setIsLoading] =
|
|
3107
|
-
const [error, setError] =
|
|
3108
|
-
const [success, setSuccess] =
|
|
3109
|
-
|
|
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
|
-
|
|
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] =
|
|
3478
|
-
const dropdownRef =
|
|
3479
|
-
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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] =
|
|
3672
|
-
const [message, setMessage] =
|
|
3673
|
-
|
|
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] =
|
|
3808
|
-
const [isLoading, setIsLoading] =
|
|
3809
|
-
const [error, setError] =
|
|
3810
|
-
const [success, setSuccess] =
|
|
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] =
|
|
3950
|
-
const [password, setPassword] =
|
|
3951
|
-
const [confirmPassword, setConfirmPassword] =
|
|
3952
|
-
const [showPassword, setShowPassword] =
|
|
3953
|
-
const [isLoading, setIsLoading] =
|
|
3954
|
-
const [error, setError] =
|
|
3955
|
-
const [success, setSuccess] =
|
|
3956
|
-
|
|
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] =
|
|
4204
|
-
const [newPassword, setNewPassword] =
|
|
4205
|
-
const [confirmPassword, setConfirmPassword] =
|
|
4206
|
-
const [showPasswords, setShowPasswords] =
|
|
4207
|
-
const [isLoading, setIsLoading] =
|
|
4208
|
-
const [error, setError] =
|
|
4209
|
-
const [success, setSuccess] =
|
|
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;
|
|
@@ -4436,6 +4471,68 @@ var ChangePassword = ({ onSuccess, appearance }) => {
|
|
|
4436
4471
|
)
|
|
4437
4472
|
] }) });
|
|
4438
4473
|
};
|
|
4474
|
+
|
|
4475
|
+
// src/react/components/utils/injectModalStyles.ts
|
|
4476
|
+
var injectModalStyles = () => {
|
|
4477
|
+
if (document.getElementById("ttf-auth-modal-styles")) {
|
|
4478
|
+
return;
|
|
4479
|
+
}
|
|
4480
|
+
const styleElement = document.createElement("style");
|
|
4481
|
+
styleElement.id = "ttf-auth-modal-styles";
|
|
4482
|
+
styleElement.textContent = `
|
|
4483
|
+
/* ImageManager Modal Styles - Critical for proper modal display */
|
|
4484
|
+
/* Radix UI Dialog styles - Force visibility */
|
|
4485
|
+
[data-radix-portal] {
|
|
4486
|
+
z-index: 99999 !important;
|
|
4487
|
+
position: fixed !important;
|
|
4488
|
+
inset: 0 !important;
|
|
4489
|
+
pointer-events: none !important;
|
|
4490
|
+
}
|
|
4491
|
+
|
|
4492
|
+
[data-radix-portal] > * {
|
|
4493
|
+
pointer-events: auto !important;
|
|
4494
|
+
}
|
|
4495
|
+
|
|
4496
|
+
/* Dialog Overlay */
|
|
4497
|
+
[data-state="open"][data-radix-dialog-overlay],
|
|
4498
|
+
[role="dialog"] + [data-radix-dialog-overlay] {
|
|
4499
|
+
position: fixed !important;
|
|
4500
|
+
inset: 0 !important;
|
|
4501
|
+
z-index: 99998 !important;
|
|
4502
|
+
background-color: rgba(0, 0, 0, 0.6) !important;
|
|
4503
|
+
pointer-events: auto !important;
|
|
4504
|
+
}
|
|
4505
|
+
|
|
4506
|
+
/* Dialog Content - Center the modal properly */
|
|
4507
|
+
[data-state="open"][data-radix-dialog-content],
|
|
4508
|
+
[role="dialog"][data-radix-dialog-content] {
|
|
4509
|
+
position: fixed !important;
|
|
4510
|
+
left: 50% !important;
|
|
4511
|
+
top: 50% !important;
|
|
4512
|
+
transform: translate(-50%, -50%) !important;
|
|
4513
|
+
z-index: 99999 !important;
|
|
4514
|
+
background: white !important;
|
|
4515
|
+
border-radius: 16px !important;
|
|
4516
|
+
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25) !important;
|
|
4517
|
+
pointer-events: auto !important;
|
|
4518
|
+
width: 95vw !important;
|
|
4519
|
+
max-width: 1280px !important;
|
|
4520
|
+
height: 90vh !important;
|
|
4521
|
+
max-height: 90vh !important;
|
|
4522
|
+
min-width: 800px !important;
|
|
4523
|
+
min-height: 600px !important;
|
|
4524
|
+
overflow: hidden !important;
|
|
4525
|
+
}
|
|
4526
|
+
|
|
4527
|
+
/* Dark mode support */
|
|
4528
|
+
.dark [data-state="open"][data-radix-dialog-content],
|
|
4529
|
+
.dark [role="dialog"][data-radix-dialog-content] {
|
|
4530
|
+
background: #0f172a !important;
|
|
4531
|
+
border: 1px solid #334155 !important;
|
|
4532
|
+
}
|
|
4533
|
+
`;
|
|
4534
|
+
document.head.appendChild(styleElement);
|
|
4535
|
+
};
|
|
4439
4536
|
var AvatarUploader = ({
|
|
4440
4537
|
onUploadComplete,
|
|
4441
4538
|
onError,
|
|
@@ -4446,32 +4543,30 @@ var AvatarUploader = ({
|
|
|
4446
4543
|
upfilesConfig,
|
|
4447
4544
|
buttonText = "Upload Avatar"
|
|
4448
4545
|
}) => {
|
|
4449
|
-
const {
|
|
4450
|
-
const [open, setOpen] =
|
|
4451
|
-
const [uploading, setUploading] =
|
|
4546
|
+
const { user, updateProfile } = useAuth();
|
|
4547
|
+
const [open, setOpen] = React.useState(false);
|
|
4548
|
+
const [uploading, setUploading] = React.useState(false);
|
|
4549
|
+
React.useEffect(() => {
|
|
4550
|
+
injectModalStyles();
|
|
4551
|
+
}, []);
|
|
4552
|
+
const effectiveFolderPath = React.useMemo(() => {
|
|
4553
|
+
if (user?.id) {
|
|
4554
|
+
return `users/${user.id}/`;
|
|
4555
|
+
}
|
|
4556
|
+
return upfilesConfig.folderPath || "/";
|
|
4557
|
+
}, [user?.id, upfilesConfig.folderPath]);
|
|
4452
4558
|
const handleSelect = async (image) => {
|
|
4453
4559
|
setUploading(true);
|
|
4454
4560
|
try {
|
|
4455
|
-
const
|
|
4456
|
-
|
|
4457
|
-
|
|
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);
|
|
4561
|
+
const response = await updateProfile({ avatar: image.url });
|
|
4562
|
+
if (response.success && response.user?.avatar) {
|
|
4563
|
+
onUploadComplete?.(response.user.avatar);
|
|
4469
4564
|
setOpen(false);
|
|
4470
4565
|
} else {
|
|
4471
|
-
throw new Error(
|
|
4566
|
+
throw new Error(response.message || "Failed to update avatar");
|
|
4472
4567
|
}
|
|
4473
4568
|
} catch (error) {
|
|
4474
|
-
const err = error instanceof Error ? error : new Error("
|
|
4569
|
+
const err = error instanceof Error ? error : new Error("Failed to update avatar");
|
|
4475
4570
|
onError?.(err);
|
|
4476
4571
|
} finally {
|
|
4477
4572
|
setUploading(false);
|
|
@@ -4501,7 +4596,7 @@ var AvatarUploader = ({
|
|
|
4501
4596
|
presignPath: upfilesConfig.presignPath
|
|
4502
4597
|
},
|
|
4503
4598
|
projectId: upfilesConfig.projectId,
|
|
4504
|
-
folderPath:
|
|
4599
|
+
folderPath: effectiveFolderPath,
|
|
4505
4600
|
title: "Select Avatar",
|
|
4506
4601
|
description: "Upload a new avatar or select from existing images.",
|
|
4507
4602
|
mode: "full",
|
|
@@ -4522,12 +4617,12 @@ var UserProfile = ({
|
|
|
4522
4617
|
}) => {
|
|
4523
4618
|
const { user, updateProfile, requestEmailChange } = useAuth();
|
|
4524
4619
|
const colors = useThemeColors();
|
|
4525
|
-
const [name, setName] =
|
|
4526
|
-
const [phoneNumber, setPhoneNumber] =
|
|
4527
|
-
const [newEmail, setNewEmail] =
|
|
4528
|
-
const [isLoading, setIsLoading] =
|
|
4529
|
-
const [error, setError] =
|
|
4530
|
-
const [success, setSuccess] =
|
|
4620
|
+
const [name, setName] = React.useState(user?.name || "");
|
|
4621
|
+
const [phoneNumber, setPhoneNumber] = React.useState(user?.phoneNumber || "");
|
|
4622
|
+
const [newEmail, setNewEmail] = React.useState("");
|
|
4623
|
+
const [isLoading, setIsLoading] = React.useState(false);
|
|
4624
|
+
const [error, setError] = React.useState(null);
|
|
4625
|
+
const [success, setSuccess] = React.useState(null);
|
|
4531
4626
|
const handleUpdateProfile = async (e) => {
|
|
4532
4627
|
e.preventDefault();
|
|
4533
4628
|
setIsLoading(true);
|
|
@@ -4818,12 +4913,27 @@ var AvatarManager = ({
|
|
|
4818
4913
|
gridClassName,
|
|
4819
4914
|
maxFileSize = 5 * 1024 * 1024,
|
|
4820
4915
|
// 5MB default
|
|
4916
|
+
maxFiles = 10,
|
|
4821
4917
|
mode = "full",
|
|
4822
4918
|
showDelete = false,
|
|
4919
|
+
autoRecordToDb = true,
|
|
4920
|
+
fetchThumbnails = true,
|
|
4921
|
+
projectId,
|
|
4922
|
+
deleteUrl,
|
|
4923
|
+
onDelete,
|
|
4823
4924
|
upfilesConfig
|
|
4824
4925
|
}) => {
|
|
4825
|
-
const { updateProfile } = useAuth();
|
|
4826
|
-
const [updating, setUpdating] =
|
|
4926
|
+
const { user, updateProfile } = useAuth();
|
|
4927
|
+
const [updating, setUpdating] = React.useState(false);
|
|
4928
|
+
React.useEffect(() => {
|
|
4929
|
+
injectModalStyles();
|
|
4930
|
+
}, []);
|
|
4931
|
+
const effectiveFolderPath = React.useMemo(() => {
|
|
4932
|
+
if (user?.id) {
|
|
4933
|
+
return `users/${user.id}/`;
|
|
4934
|
+
}
|
|
4935
|
+
return upfilesConfig.folderPath || "/";
|
|
4936
|
+
}, [user?.id, upfilesConfig.folderPath]);
|
|
4827
4937
|
const handleSelect = async (image) => {
|
|
4828
4938
|
setUpdating(true);
|
|
4829
4939
|
try {
|
|
@@ -4851,18 +4961,25 @@ var AvatarManager = ({
|
|
|
4851
4961
|
apiKey: upfilesConfig.apiKey,
|
|
4852
4962
|
apiKeyHeader: upfilesConfig.apiKeyHeader || "authorization",
|
|
4853
4963
|
presignUrl: upfilesConfig.presignUrl,
|
|
4854
|
-
presignPath: upfilesConfig.presignPath
|
|
4964
|
+
presignPath: upfilesConfig.presignPath,
|
|
4965
|
+
headers: upfilesConfig.headers,
|
|
4966
|
+
withCredentials: upfilesConfig.withCredentials
|
|
4855
4967
|
},
|
|
4856
|
-
|
|
4968
|
+
projectId,
|
|
4969
|
+
folderPath: effectiveFolderPath,
|
|
4857
4970
|
title,
|
|
4858
4971
|
description,
|
|
4859
4972
|
className,
|
|
4860
4973
|
gridClassName,
|
|
4861
4974
|
onSelect: handleSelect,
|
|
4975
|
+
onDelete,
|
|
4976
|
+
deleteUrl,
|
|
4977
|
+
autoRecordToDb,
|
|
4978
|
+
fetchThumbnails,
|
|
4862
4979
|
maxFileSize,
|
|
4980
|
+
maxFiles,
|
|
4863
4981
|
mode,
|
|
4864
|
-
showDelete
|
|
4865
|
-
fetchThumbnails: true
|
|
4982
|
+
showDelete
|
|
4866
4983
|
}
|
|
4867
4984
|
);
|
|
4868
4985
|
};
|