mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-01-20 16:49:46 -06:00
Add several endpoints
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -8,7 +8,7 @@ const withAdminCheck = (WrappedComponent) => {
|
||||
|
||||
useEffect(() => {
|
||||
axiosInstance
|
||||
.get("/auth/users/admin")
|
||||
.doesAdminExist()
|
||||
.then((response) => {
|
||||
if (response.data.data === true) {
|
||||
navigate("/login");
|
||||
|
||||
@@ -249,7 +249,7 @@ const Login = () => {
|
||||
|
||||
useEffect(() => {
|
||||
axiosInstance
|
||||
.get("/auth/users/admin")
|
||||
.doesAdminExist()
|
||||
.then((response) => {
|
||||
if (response.data.data === false) {
|
||||
navigate("/register");
|
||||
|
||||
@@ -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 });
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user