Added check to verify and fetch token from server
This commit is contained in:
1 parent
39d78ac4d7
commit
c77414f2d7
7 files changed
+61
-3
No files matched your search
@@ -10,6 +10,7 @@ const {
|
||||
deleteUserParamValidation,
|
||||
inviteRoleValidation,
|
||||
inviteBodyValidation,
|
||||
inviteVerifciationBodyValidation,
|
||||
} = require("../validation/joi");
|
||||
const logger = require("../utils/logger");
|
||||
require("dotenv").config();
|
||||
@@ -237,6 +238,21 @@ const inviteController = async (req, res, next) => {
|
||||
}
|
||||
};
|
||||
|
||||
const inviteVerifyController = async (req, res, next) => {
|
||||
try {
|
||||
await inviteVerifciationBodyValidation.validateAsync(req.body);
|
||||
const invite = await req.db.getInviteToken(req, res);
|
||||
|
||||
res
|
||||
.status(200)
|
||||
.json({ status: "success", msg: "Invite verified", data: invite });
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
next(error);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks to see if an admin account exists
|
||||
* @async
|
||||
@@ -445,6 +461,7 @@ module.exports = {
|
||||
loginController,
|
||||
userEditController,
|
||||
inviteController,
|
||||
inviteVerifyController,
|
||||
checkAdminController,
|
||||
recoveryRequestController,
|
||||
validateRecoveryTokenController,
|
||||
|
||||
@@ -185,6 +185,21 @@ const requestInviteToken = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
const getInviteToken = async (req, res) => {
|
||||
try {
|
||||
console.log(req.body.token);
|
||||
const invite = await InviteToken.findOneAndDelete({
|
||||
token: req.body.token,
|
||||
});
|
||||
if (invite === null) {
|
||||
throw new Error(errorMessages.AUTH_INVITE_NOT_FOUND);
|
||||
}
|
||||
return invite;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Request a recovery token
|
||||
* @async
|
||||
@@ -695,6 +710,7 @@ module.exports = {
|
||||
deleteUser,
|
||||
getAllUsers,
|
||||
requestInviteToken,
|
||||
getInviteToken,
|
||||
requestRecoveryToken,
|
||||
validateRecoveryToken,
|
||||
resetPassword,
|
||||
|
||||
@@ -17,6 +17,7 @@ const {
|
||||
getAllUsersController,
|
||||
deleteUserController,
|
||||
inviteController,
|
||||
inviteVerifyController,
|
||||
} = require("../controllers/authController");
|
||||
|
||||
//Auth routes
|
||||
@@ -38,6 +39,7 @@ router.delete(
|
||||
);
|
||||
|
||||
router.post("/invite", verifyJWT, inviteController);
|
||||
router.post("/invite/verify", inviteVerifyController);
|
||||
|
||||
//Recovery routes
|
||||
router.post("/recovery/request", recoveryRequestController);
|
||||
|
||||
@@ -6,6 +6,7 @@ const errorMessages = {
|
||||
// Auth Controller
|
||||
UNAUTHORIZED: "Unauthorized access",
|
||||
AUTH_ADMIN_EXISTS: "Admin already exists",
|
||||
AUTH_INVITE_NOT_FOUND: "Invite not found",
|
||||
|
||||
//Error handling middleware
|
||||
UNKNOWN_SERVICE: "Unknown service",
|
||||
|
||||
@@ -112,6 +112,10 @@ const inviteBodyValidation = joi.object({
|
||||
}),
|
||||
});
|
||||
|
||||
const inviteVerifciationBodyValidation = joi.object({
|
||||
token: joi.string().required(),
|
||||
});
|
||||
|
||||
//****************************************
|
||||
// Monitors
|
||||
//****************************************
|
||||
@@ -239,6 +243,7 @@ module.exports = {
|
||||
newPasswordValidation,
|
||||
inviteRoleValidation,
|
||||
inviteBodyValidation,
|
||||
inviteVerifciationBodyValidation,
|
||||
getMonitorByIdValidation,
|
||||
getMonitorsByUserIdValidation,
|
||||
monitorValidation,
|
||||
|
||||
Reference in new issue
Block a user