user managment

This commit is contained in:
2024-06-24 18:37:04 +02:00
parent bafef0f6b3
commit 0c7fc6fdf7
50 changed files with 2748 additions and 219 deletions
+33
View File
@@ -0,0 +1,33 @@
function checkIsConcernedUserOrAdmin(req, res, next) {
const user = req.user; // User is set by Passport
const userIdParam = req.params.id;
if (user.isAdmin === true || user._id === userIdParam) {
next();
} else {
res.status(403).json({ error: 'Forbidden' });
}
}
function checkIsAdmin(req, res, next) {
const user = req.user; // User is set by Passport
if (user.isAdmin === true) {
next();
} else {
res.status(403).json({ error: 'Forbidden' });
}
}
function checkIsAgent(req, res, next) {
const user = req.user; // User is set by Passport
if (user.isAgent === true) {
next();
} else {
res.status(403).json({ error: 'Forbidden' });
}
}
module.exports = { checkIsConcernedUserOrAdmin, checkIsAgent, checkIsAdmin };