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

chapter-03- express-jwt #147

Open
inatu opened this issue May 9, 2022 · 9 comments
Open

chapter-03- express-jwt #147

inatu opened this issue May 9, 2022 · 9 comments

Comments

@inatu
Copy link

inatu commented May 9, 2022

Hello,
It seems that this code broke at "express-jwt": "^7.7.0"

How could I modify this code to work on the the latest version

const requireSignin = expressJwt({
secret: config.jwtSecret,
userProperty: 'auth'
})

got the following error:

const requireSignin = express_jwt__WEBPACK_IMPORTED_MODULE_2___default()({
^

TypeError: express_jwt__WEBPACK_IMPORTED_MODULE_2___default(...) is not a function
at eval (webpack://user_backend/./server/controllers/auth.controller.js?:69:73)
at Object../server/controllers/auth.controller.js (/Users/natu/qingning_website/user_backend/dist/server.generated.js:29:1)
at webpack_require (/Users/natu/qingning_website/user_backend/dist/server.generated.js:243:41)
at eval (webpack://user_backend/./server/routes/user.routes.js?:8:86)
at Object../server/routes/user.routes.js (/Users/natu/qingning_website/user_backend/dist/server.generated.js:79:1)
at webpack_require (/Users/natu/qingning_website/user_backend/dist/server.generated.js:243:41)
at eval (webpack://user_backend/./server/express.js?:20:77)
at Object../server/express.js (/Users/natu/qingning_website/user_backend/dist/server.generated.js:49:1)
at webpack_require (/Users/natu/qingning_website/user_backend/dist/server.generated.js:243:41)
at eval (webpack://user_backend/./server/server.js?:3:66)

@uladaharanina
Copy link

uladaharanina commented May 24, 2022

Hi, I believe we need to do this:

const requireSignin = () => expressJwt({
secret: config.jwtSecret,
userProperty: 'auth'
});

And in the user.routes.js apply () to requireSignin.

router.route('/api/users/:userId')
.get(authCtrl.requireSignin(), userCtrl.read)
.put(authCtrl.requireSignin(), authCtrl.hasAuthorization, userCtrl.update)
.delete(authCtrl.requireSignin(), authCtrl.hasAuthorization, userCtrl.remove)

@shruthis-shetty
Copy link
Collaborator

Hi @inatu , did you got the solution to this issue or still having any issues?
Please reply here the update.

@JimmyJoggins
Copy link

With "express-jwt": "^8.4.1"

Try adding algorithms as follows:

const requireSignin = expressJwt({
secret: config.jwtSecret,
userProperty: 'auth',
algorithms: ["HS256"]
})

The above approach worked for me. No need to convert authCtrl.requireSignin to a function.

@shruthis-shetty
Copy link
Collaborator

Hi @inatu , @JimmyJoggins and @wadewilsones , anyone of you please confirm me whether we are good to close this issue?

@JimmyJoggins
Copy link

Given the level of inactivity, I think probably yes.

@Apurv-Salunke
Copy link

@inatu I am getting the exact same error. How did you resolve it ?

@Apurv-Salunke
Copy link

webpack:///./server/controllers/auth.controller.js?:54
const requireSignin = express_jwt__WEBPACK_IMPORTED_MODULE_2___default()({
^

TypeError: express_jwt__WEBPACK_IMPORTED_MODULE_2___default(...) is not a function
at eval (webpack:///./server/controllers/auth.controller.js?:54:73)
at ./server/controllers/auth.controller.js (/media/apurv/work space/academic projects/mern-stack/social-media/dist/server.generated.js:29:1)
at webpack_require (/media/apurv/work space/academic projects/mern-stack/social-media/dist/server.generated.js:233:41)
at eval (webpack:///./server/routes/user.routes.js?:8:86)
at ./server/routes/user.routes.js (/media/apurv/work space/academic projects/mern-stack/social-media/dist/server.generated.js:89:1)
at webpack_require (/media/apurv/work space/academic projects/mern-stack/social-media/dist/server.generated.js:233:41)
at eval (webpack:///./server/express.js?:18:77)
at ./server/express.js (/media/apurv/work space/academic projects/mern-stack/social-media/dist/server.generated.js:49:1)
at webpack_require (/media/apurv/work space/academic projects/mern-stack/social-media/dist/server.generated.js:233:41)
at eval (webpack:///./server/server.js?:3:66)

Node.js v18.16.0

@oriankeith002
Copy link

webpack:///./server/controllers/auth.controller.js?:54 const requireSignin = express_jwt__WEBPACK_IMPORTED_MODULE_2___default()({ ^

TypeError: express_jwt__WEBPACK_IMPORTED_MODULE_2___default(...) is not a function at eval (webpack:///./server/controllers/auth.controller.js?:54:73) at ./server/controllers/auth.controller.js (/media/apurv/work space/academic projects/mern-stack/social-media/dist/server.generated.js:29:1) at webpack_require (/media/apurv/work space/academic projects/mern-stack/social-media/dist/server.generated.js:233:41) at eval (webpack:///./server/routes/user.routes.js?:8:86) at ./server/routes/user.routes.js (/media/apurv/work space/academic projects/mern-stack/social-media/dist/server.generated.js:89:1) at webpack_require (/media/apurv/work space/academic projects/mern-stack/social-media/dist/server.generated.js:233:41) at eval (webpack:///./server/express.js?:18:77) at ./server/express.js (/media/apurv/work space/academic projects/mern-stack/social-media/dist/server.generated.js:49:1) at webpack_require (/media/apurv/work space/academic projects/mern-stack/social-media/dist/server.generated.js:233:41) at eval (webpack:///./server/server.js?:3:66)

Node.js v18.16.0

Hi, import express jwt with a different syntaxt

@oriankeith002
Copy link

let { expressjwt: expressJwt } = require('express-jwt');

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

No branches or pull requests

6 participants