text: const { User } = require('../models/User');
  const jwt = require('jsonwebtoken');
  const config = require('config');
  
  module.exports = (req, res, next) => {
    const token = req.header('x-auth-token');
    // Checking if token exist
    if (!token) {
      return res.status(401).json({ msg: 'No token, authorization denied' });
    }
    // Verify token
    try {
      const decoded = jwt.verify(token, config.get('jwtSecret'));
      req.user = decoded.user;
      next();
    } catch (error) {
      res.status(401).json({ msg: 'Token is invalid' });
    }
  };
  