Skip to content
New issue

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

Why am I getting an error saying that expressJwt is not a function? #27

Open
nadunchanna98 opened this issue Dec 17, 2022 · 3 comments
Open

Comments

@nadunchanna98
Copy link

typeerror: expressjwt is not a function
   at authjwt (e:\app\node js\e-school mobile app\e-school-mobile-app\backend\helpers\jwt.js:8:12)
   at layer.handle [as handle_request] (e:\app\node js\e-school mobile app\e-school-mobile-app\backend\node_modules\express\lib\router\layer.js:95:5)
   at trim_prefix

@ashaller2017
Copy link

ashaller2017 commented Nov 5, 2023

can you show how you import it?
const expressJwt = require('express-jwt');

expressJwt.expressjwt({ secret: secret, algorithms: ["HS256"], isRevoked: isRevoked, })
you may just need to deconstruct it or explicitly declare it

@NuralamMRH
Copy link

Work with me :

const 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: //public/uploads(.)/, methods: ["GET", "OPTIONS"] },
{ 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) {
try {
// Check if the user should be revoked based on some condition
if (!payload.isAdmin) {
// User is not admin, revoke the token
return done(null, true);
}

// User is authorized, don't revoke the token
return done(null, false);

} catch (error) {
// If an error occurs, consider it as token revocation and revoke the token
return done(error, true);
}
}

module.exports = authJwt;

@Bratini89
Copy link

can you show how you import it? const expressJwt = require('express-jwt');

expressJwt.expressjwt({ secret: secret, algorithms: ["HS256"], isRevoked: isRevoked, }) you may just need to deconstruct it or explicitly declare it

The best answer so far I was stucked with this error and thanks to this i have resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants