feat(admin): add add-music api
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import User from '../models/User.js';
|
||||
|
||||
export const requireAdmin = async (req, res, next) => {
|
||||
try {
|
||||
if (!req.userId) {
|
||||
return res.status(401).json({ success: false, message: 'Unauthorized' });
|
||||
}
|
||||
|
||||
const user = await User.findById(req.userId).select('role').lean();
|
||||
if (!user || user.role !== 'admin') {
|
||||
return res.status(403).json({ success: false, message: 'Forbidden' });
|
||||
}
|
||||
|
||||
return next();
|
||||
} catch (error) {
|
||||
return next(error);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user