In my index.js I have this middlewareapp.use(/^\/api\/(?!account)/, session(sessionObj), authenticate);If I'm not wrong, the regex is saying, any url that is /api/ not following account. So if I go /api/account, this app.use won't be called.When I use postman to call a PATCH request to /api/auth/account/close/confirm, it seems to be skipping the app.use middleware.In the /api/auth/account/close/confirm middleware, it starts withif (req.session.user) { // do stuff with authenticate user } else { // send user not found response } and postman throws a TypeError, cannot read property 'user' of undefined. So it appears that it's going directly to the /api/auth/account/close/confirm middleware.The authenticate variable is a middleware that authenticates the user and the code is like somodule.exports = (req, resp, next) => { console.log(req.session) if (req.body.username && req.body.password) { // login } else { next(); } } The console.log here did not show in console, meaning that this middleware was not called.Do direct requests from software like postman not take the app.use into consideration or am I setting my server app wrong? When I make requests from my app on client side, it goes through the authenticate process.
Submitted September 17, 2019 at 07:32AM by eggtart_prince
No comments:
Post a Comment