-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc11df6
commit 1ab9c6c
Showing
37 changed files
with
7,741 additions
and
3,293 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const User = require('../models/User'); | ||
|
||
// Middleware to check if user is admin | ||
exports.isAdmin = async (req, res, next) => { | ||
try { | ||
const user = await User.findById(req.user.userId); | ||
if (!user) { | ||
return res.status(404).json({ message: 'User not found' }); | ||
} | ||
|
||
if (user.role !== 'admin') { | ||
return res.status(403).json({ message: 'Access denied. Admin only.' }); | ||
} | ||
|
||
next(); | ||
} catch (error) { | ||
console.error('Role check error:', error); | ||
res.status(500).json({ message: 'Server error during role check' }); | ||
} | ||
}; |
Oops, something went wrong.