diff --git a/Client/src/Components/TabPanels/Account/TeamPanel.jsx b/Client/src/Components/TabPanels/Account/TeamPanel.jsx index 553397f89..3ff948a26 100644 --- a/Client/src/Components/TabPanels/Account/TeamPanel.jsx +++ b/Client/src/Components/TabPanels/Account/TeamPanel.jsx @@ -52,10 +52,7 @@ const TeamPanel = () => { useEffect(() => { const fetchTeam = async () => { try { - const response = await axiosInstance.get("/auth/users", { - headers: { Authorization: `Bearer ${authToken}` }, - }); - + const response = await axiosInstance.getAllUsers(authToken); setMembers(response.data.data); } catch (error) { createToast({ diff --git a/Client/src/HOC/withAdminCheck.jsx b/Client/src/HOC/withAdminCheck.jsx index 60c0ea088..c6a939679 100644 --- a/Client/src/HOC/withAdminCheck.jsx +++ b/Client/src/HOC/withAdminCheck.jsx @@ -8,7 +8,7 @@ const withAdminCheck = (WrappedComponent) => { useEffect(() => { axiosInstance - .get("/auth/users/admin") + .doesAdminExist() .then((response) => { if (response.data.data === true) { navigate("/login"); diff --git a/Client/src/Pages/Auth/Login.jsx b/Client/src/Pages/Auth/Login.jsx index d1f251925..6a408c970 100644 --- a/Client/src/Pages/Auth/Login.jsx +++ b/Client/src/Pages/Auth/Login.jsx @@ -249,7 +249,7 @@ const Login = () => { useEffect(() => { axiosInstance - .get("/auth/users/admin") + .doesAdminExist() .then((response) => { if (response.data.data === false) { navigate("/register"); diff --git a/Client/src/Pages/Auth/Register/Register.jsx b/Client/src/Pages/Auth/Register/Register.jsx index 8a4c57f0e..1dedaa0f1 100644 --- a/Client/src/Pages/Auth/Register/Register.jsx +++ b/Client/src/Pages/Auth/Register/Register.jsx @@ -397,9 +397,7 @@ const Register = ({ isAdmin }) => { const fetchInvite = async () => { if (token !== undefined) { try { - const res = await axiosInstance.post(`/auth/invite/verify`, { - token, - }); + const res = await axiosInstance.verifyInvitationToken(token); const { role, email } = res.data.data; console.log(role); setForm({ ...form, email, role }); diff --git a/Client/src/Utils/NetworkService.js b/Client/src/Utils/NetworkService.js index 093210f90..58ef2951f 100644 --- a/Client/src/Utils/NetworkService.js +++ b/Client/src/Utils/NetworkService.js @@ -151,4 +151,29 @@ axiosInstance.setNewPassword = async (recoveryToken, form) => { }); }; +// ********************************** +// Check for admin user +// ********************************** +axiosInstance.doesAdminExist = async () => { + return axiosInstance.get("/auth/users/admin"); +}; + +// ********************************** +// Get all users +// ********************************** +axiosInstance.getAllUsers = async (authToken) => { + return axiosInstance.get("/auth/users", { + headers: { Authorization: `Bearer ${authToken}` }, + }); +}; + +// ********************************** +// Verify Invitation Token +// ********************************** +axiosInstance.verifyInvitationToken = async (token) => { + return axiosInstance.post(`/auth/invite/verify`, { + token, + }); +}; + export default axiosInstance;