Task Name: "Create Middleware to Check User Roles" Description: "Generate middleware to…
- User
Task Name: "Create Middleware to Check User Roles" Description: "Generate middleware to protect specific routes based on user roles (Admin, Project Manager, Team Member)" Requirements: 1. Database: mongoose 2. Output needed: Return only the middleware function code
code3. Tasks to implement: Create a middleware function to evaluate user roles.,Export: exports.checkUserRole = (roles) => {...}, Import User schema from '../models/User.js'., Use JWT to decode token and retrieve user information., Check if the user's role is included in the specified roles array., If user role matches, proceed to the next middleware; otherwise, respond with an access denied message., Use the middleware function to protect specific routes based on user roles.
code4. Supporting data Please generate the code for above tasks, following the instructions and including comments for clarity and logic for Dependencies must needed. While creating router for specifict file your have to read supporing file data and create for that **Output Formats**:Return dependencies like this
const bcrypt = require('bcrypt');in this formatedependenciesconst bcrypt = require('bcrypt');Ensure this format is consistently followed in responses.
- Assistantdependencies
const jwt = require('jsonwebtoken'); const mongoose = require('mongoose');javascript