I am new in nodejs,expressjs and trying to authenticate routes using express-jwt package by creating a middleware. Everything is working fine with GET routes but when I am access POST routes and trying to revoke a token, it returns me 500 internal server error without any message. I am very confused that what is the main reason behind this. So guys please help me if possible. My code is as following.
const { expressjwt: expressJwt } = require('express-jwt');
function authJwt() {
const secret = process.env.secret;
const api = process.env.API_URL;
return expressJwt({
secret,
algorithms: ['HS256'],
isRevoked: isRevoked
}).unless({
path: [
{url: /\/api\/v1\/products(.*)/ , methods: ['GET', 'OPTIONS'] },
{url: /\/api\/v1\/categories(.*)/ , methods: ['GET', 'OPTIONS'] },
`${api}/users/login`,
`${api}/users/register`,
]
})
}
async function isRevoked(req,payload,done) {
if(!payload.isAdmin) {
return done(null, true);
}
done();
}
module.exports = authJwt