Skip to content

Commit

Permalink
fix: Updating ui and other elements
Browse files Browse the repository at this point in the history
  • Loading branch information
AdibSadman192 committed Nov 27, 2024
1 parent dc11df6 commit 1ab9c6c
Show file tree
Hide file tree
Showing 37 changed files with 7,741 additions and 3,293 deletions.
20 changes: 20 additions & 0 deletions backend/middleware/roleCheck.js
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' });
}
};
Loading

0 comments on commit 1ab9c6c

Please sign in to comment.