import {tokenPrivateKey} from "../../utils/constans/signUp";
import userNotFound from '../../utils/customErrors/userNotFound';
const jwt = require('jsonwebtoken');

module.exports = (req, res, next) => {

    jwt.verify(req.headers.auth, tokenPrivateKey, (err, decoded) => {
        if(err) {
            next(new userNotFound());
        }else {
            req.body.id = decoded.id;
            req.body.role = decoded.role;
            next();
        }
    });
};