Closed ghost closed 3 years ago
You aren't passing an options
object as the second argument, that is what the error is telling you. The second argument to jwt.sign
needs to be an object and you are passing process.env.JWT_SECRET_KEY
which will be a string an not an object.
You should be setting the secret
of fastify-jwt
when you register the plugin.
https://github.com/fastify/fastify-jwt#usage
fastify.register(require('fastify-jwt'), {
secret: 'supersecret'
})
You aren't passing an
options
object as the second argument, that is what the error is telling you. The second argument tojwt.sign
needs to be an object and you are passingprocess.env.JWT_SECRET_KEY
which will be a string an not an object.You should be setting the
secret
offastify-jwt
when you register the plugin.https://github.com/fastify/fastify-jwt#usage
fastify.register(require('fastify-jwt'), { secret: 'supersecret' })
It worked thanks. (I've removed the secret from the signing) My issue is here that the part that you have linked here says this:
Register as a plugin. This will decorate your fastify instance with the >>> standard jsonwebtoken methods decode, sign, and verify <<<; refer to their documentation to find how to use the utilities. It will also register request.jwtVerify and reply.jwtSign. You must pass a secret when registering the plugin.
To make it easier to see let me cut it out
standard jsonwebtoken methods decode, sign, and verify
refer to their documentation to find how to use the utilities.
"Their" JWT documentation says that signing takes a payload, secret and options. So this means that the fastify-jwt and JWT mothods aren't the same.
Short said, the part that you've linked causes confusion.
I would say that everything is clear now and the Documentation of fastify-jwt is misleading. Yes, I could think of this but by saying "The jsonwebtokens methods are the same in fastify-jwt" is just misleading. Someone should definitely add some info that the secrets don't need to be passed.
💬 Question here
I've made the whole login/signing part, now I need to create the JWT part and I'm unable to sign my JWT token. I'm getting the wollowing error:
Expected "options" to be a plain object
Your Environment
Terminal Log
Must be a bug because when using normal JWT module it works.