text: /* eslint-env es6, node */
  import jwt from 'jsonwebtoken'
  
  const auth = (req, res, next) => {
    const token = req.header ('x-auth-token')
  
    if (!token) {
      return res.status (401).json ({msg: 'No token, authorization denied'})
    }
  
    try {
      const decoded = jwt.verify (token, process.env.JWT_SECRET)
      req.user = decoded
      next ()
    } catch (err) {
      res.status (400).json ({msg: 'Token is not valid'})
    }
  }
  
  export default auth
  