Skip to content

Commit

Permalink
fix: propagate user result (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eomm authored Mar 5, 2023
1 parent 271eabe commit b276481
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion jwt.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ function fastifyJwt (fastify, options, next) {
maybePromise
.then(trusted => trusted ? callback(null, result) : callback(new AuthorizationTokenUntrustedError()))
} else if (maybePromise) {
callback(null, maybePromise)
callback(null, result)
} else {
callback(new AuthorizationTokenUntrustedError())
}
Expand Down
8 changes: 6 additions & 2 deletions test/jwt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1357,13 +1357,15 @@ test('sign and verify with RSA/ECDSA certificates and global options', function
test('sign and verify with trusted token', function (t) {
t.plan(2)
t.test('Trusted token verification', function (t) {
t.plan(1)
t.plan(2)

const f = Fastify()
f.register(jwt, { secret: 'test', trusted: (request, { jti }) => jti !== 'untrusted' })
f.get('/', (request, reply) => {
request.jwtVerify()
.then(function (decodedToken) {
delete decodedToken?.iat
t.same(decodedToken, { foo: 'bar', jti: 'trusted' })
return reply.send(decodedToken)
})
.catch(function (error) {
Expand All @@ -1385,13 +1387,15 @@ test('sign and verify with trusted token', function (t) {
})

t.test('Trusted token - async verification', function (t) {
t.plan(1)
t.plan(2)

const f = Fastify()
f.register(jwt, { secret: 'test', trusted: (request, { jti }) => Promise.resolve(jti !== 'untrusted') })
f.get('/', (request, reply) => {
request.jwtVerify()
.then(function (decodedToken) {
delete decodedToken?.iat
t.same(decodedToken, { foo: 'bar', jti: 'trusted' })
return reply.send(decodedToken)
})
.catch(function (error) {
Expand Down

0 comments on commit b276481

Please sign in to comment.