Description: add role based access in this check the user based on the role from the…
- User
Description: add role based access in this check the user based on the role from the token. check the user based on role from db, User db adn Admin db. admin role will be 'admin', User will be 'user'
const jwt = require('jsonwebtoken');
const accessTokenSecret = 'userSS'; const refreshTokenSecret = 'userSS';
// Middleware to verify access token const verifyAccessToken = (req, res, next) => { const token = req.headers['authorization']?.split(' ')[1]; console.log(req.headers, token) if (!token) return res.status(403).json({ error: 'Your not authorized to user this service' });
codejwt.verify(token, accessTokenSecret, (err, user) => { if (err) return res.status(403).json({ error: 'Your not authorized to user this service' }); req.user = user; next(); });};
// Middleware to verify refresh token const verifyRefreshToken = (req, res, next) => { const token = req.body.refreshToken; if (!token) return res.sendStatus(403);
codejwt.verify(token, refreshTokenSecret, (err, user) => { if (err) return res.sendStatus(403); req.user = user; next(); });};
codeGenerate source code based on the description above and respond in the following JSON format ONLY: ```json { "name": "prompt_name", "schema": { "type": "string", "code": "Generated code here" } } ``` IMPORTANT: - Ensure the JSON response is error-free. - Include no additional text or explanations. Respond with the JSON object only. - Assistantjson