const jwt = require("jsonwebtoken"); const config = require("../../config/auth.config.js"); const db = require("../models"); const User = db.user; exports.verifyToken = (req, res, next) => { let authData = req.headers.authorization; if(!authData) { return res.status(403).send({ message: 'No token provided!' }) } let token = authData.split(' ')[1]; jwt.verify(token, config.secret, (err, decoded) => { if(err) { return res.status(401).send({ message: "Unauthorized!" }) } req.userId = decoded.id; next() }) };