We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
As reported here:
https://stackoverflow.com/questions/49831398/retrieve-username-from-jwt-token-using-fastify
I am able to create a jwt token:
fastify.post('/signup', (req, reply) => { const token = fastify.jwt.sign({ payload, }) reply.send({ token }) })
that can return something like:
{"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1MjM3MDgyMzF9.HZqqiL7wwPaEQihUGoF7Y42Ia67HgKJ-1Ms38Nvcsmw"}
but if I try to decode the username frmo token
fastify.get('/decode', async (request, reply) => { const auth = request.headers.authorization; const token = auth.split(' ')[1] fastify.jwt.verify(token, (err, decoded) => { if (err) fastify.log.error(err) fastify.log.info('username : ' + decoded.username) reply.send({ foo: decoded, }) }) })
the response is:
{"foo":{"iat":1523660987}}
The text was updated successfully, but these errors were encountered:
Can you upload a full example that reproduces the issue?
Sorry, something went wrong.
No sorry. But I'd found the solution (or the problem) ^_^. In /signup endpoint I've sent {payload:{username:"foo"}}.
/signup
{payload:{username:"foo"}}
In the wrong code fastify.log.info('username : ' + decoded.username) I've fixed with fastify.log.info('username : ' + decoded.payload.username)
fastify.log.info('username : ' + decoded.username)
fastify.log.info('username : ' + decoded.payload.username)
No branches or pull requests
As reported here:
https://stackoverflow.com/questions/49831398/retrieve-username-from-jwt-token-using-fastify
I am able to create a jwt token:
that can return something like:
but if I try to decode the username frmo token
the response is:
The text was updated successfully, but these errors were encountered: