added roles with checking in middleware
- still need signup for orgs - login for admin
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
const jwt = require('jsonwebtoken'),
|
||||
errorMaker = require('../helpers/error.maker');
|
||||
|
||||
module.exports = (req, res, next) => {
|
||||
module.exports = role => (req, res, next) => {
|
||||
try {
|
||||
const token = req.headers.authorization.split(' ')[1];
|
||||
const decoded = jwt.verify(token, process.env.JWT_KEY);
|
||||
req.user_data = decoded; //for use till end of request
|
||||
req.user = decoded; //for use till end of request
|
||||
|
||||
if (role != req.user.role) {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
next();
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user