You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

16 lines
439 B

6 months ago
export const requireAuth = (req, res, next) => {
if (!req.user) {
return res.status(401).json({ error: 'You must be logged in.' });
}
next();
};
export const requireAdmin = (req, res, next) => {
if (!req.user) {
return res.status(401).json({ error: 'You must be logged in.' });
}
if (req.user.role !== 'admin') {
return res.status(403).json({ error: 'Access denied. Admin privileges required.' });
}
next();
};