Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: expressJwt is not a function

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.

like image 866
user9507446 Avatar asked May 07 '26 10:05

user9507446


1 Answers

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"],
});
like image 188
Alaindeseine Avatar answered May 10 '26 01:05

Alaindeseine