I'm trying to write middleware for user authorization in my app. I use this function to check if a route requires being sign in. The code is as follows:
const { expressJwt } = require('express-jwt');
exports.requireSignin = expressJwt({
secret: process.env.JWT_SECRET,
algorithms: ["HS256"],
userProperty: "auth",});
However, I get the following error:
TypeError: expressJwt is not a function at Object.<anonymous> (path to the file)\
What could be the problem? None of the other answers seem to be helpful.
2023 UPDATE
With version greater than 7.x, use this as doc said (https://www.npmjs.com/package/express-jwt) :
const { expressjwt: jwt } = require("express-jwt");
Then you can use jwt:
jwt({
secret: "shhhhhhared-secret",
audience: "http://myapi/protected",
issuer: "http://issuer",
algorithms: ["HS256"],
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With