title: Why is jsonwebtoken throwing an "invalid signature" error?
body: <p>I am using the jsonwebtoken package (<a href="https://github.com/auth0/node-jsonwebtoken" rel="noreferrer">https://github.com/auth0/node-jsonwebtoken</a>) to handle JWTs in my project.  No matter what I try, it gives me this error: <code>name: 'JsonWebTokenError', message: 'invalid signature'</code></p>
  
  <p>Here is where I sign the JWT:</p>
  
  <pre><code>const addBearerToken = (myUser, cb) =&gt; {
    jwt.sign({user: myUser, userId: myUser.id}, 'helloworld', (err, token) =&gt; {
      if (err) return (err, null)
      userRepo.update(myUser._id, {authToken: token}, (err, myUser) =&gt; {
        if (err) {
          return cb(err, null)
        } else {
          return cb(null, token)
        }
      })
    })
  }
  </code></pre>
  
  <p>And here is where I try to verify it:</p>
  
  <pre><code>const checkForJWT = (req, res, next) =&gt; {
    let bearerHeader = req.header('Authorization').split(' ')
    let token = bearerHeader[1]
    console.log(token + '  ||  token')
    jwt.verify(token, 'helloworld', (err, decoded) =&gt; {
      if (err) {
        console.log(err)
        return (err, null) // this is where the error is thrown
      } else {
      ...
      }
    })
  }
  </code></pre>
  
  <p>I'm using 'helloworld' as a stand in for my secret key.  I suspect the problem is with the secret key but like i said, I'm not sure what is going on behind the scenes that is causing this error.</p>
  
  <p>If I use jwt.decode(token, 'helloworld') I get all the right information back.  But I get the error when i use jwt.verify().</p>
  
  <p>Any help is much appreciated.  Let me know if you need any more information from my code.</p>