title: JWT gives JsonWebTokenError "invalid token"
body: <p>I have used <code>jsonwebtoken</code> for token verification in my Node Application .
  Here <code>jwt.sign</code> works perfectly . But when <code>jwt.verify</code> gives following error</p>
  
  <blockquote>
    <p>"auth": false,
        "message": {
            "name": "JsonWebTokenError",
            "message": "invalid token"
        }
    } </p>
  </blockquote>
  
  <p>Here is my Post and Get Router</p>
  
  <pre><code>router.post('/signup',(req,res)=&gt;{
      const body = _.pick(req.body,['username','email_id','name','college','password','dob','gender','city','joinedOn','bio']);
      User.findOne({'username':body.username},function(err,user){
          if(err){
              res.status(404).send(err)
          }else if(user){
              res.status(404).send('User with Username Exists')
          }else{
              var user = new User(body);
              user.save().then((user) =&gt; {
                  var token = jwt.sign({ username: user.username},'secret', {
                      "algorithm": "HS256",
                      expiresIn: 86400 // expires in 24 hours
                    });
                    res.status(200).send({ auth: true, token: token });
                }, (e) =&gt; {
                  res.status(400).send(e)
                })
          }
      })
  
  });
  
  router.get('/me', VerifyToken, function(req, res) {
  
      User.findOne({username:req.username}, function (err, user) {
          if (err) return res.status(500).send(err);
          if (!user) return res.status(404).send("No user found.");
          res.status(200).send(user);
        });
  
  });
  </code></pre>
  
  <p>Below is verifyToken Function</p>
  
  <pre><code>function verifyToken(req, res, next) {
    var token =  req.headers['x-access-token'];
    if (!token)
      return res.status(403).send({ auth: false, message: 'No token provided.' });
      console.log(token)
    jwt.verify(token,'secret', function(err, decoded) {
      if (err)
      return res.status(500).send({ auth: false, message: err }); 
      //req.username = decoded.username;
      console.log(decoded)
      next();
    });
  }
  </code></pre>
  
  <p>I can't figure out what's wrong in my program .Any suggestions would be appreciated .
  Thanks</p>