Note that there are some explanatory texts on larger screens.

plurals
  1. POexpress authentication middleware failing to redirect correctly after a PUT request
    primarykey
    data
    text
    <p>I'm using passportjs with a middleware below. It is suppose to check if the user is login when he requests certain things. If he is not signed in, he should be redirected to the login page. </p> <p>I have a request route as follows: </p> <pre><code>app.put('/fantasyteams/:fantasyTeamId', auth.requiresLogin, fantasyteams.update); </code></pre> <p>This route will be called when the user tries to update a resource called Fantasy Team in the website</p> <p>auth.requiresLogin is a middleware as follows:</p> <pre><code>exports.requiresLogin = function (req, res, next) { if (req.isAuthenticated()) { return next() } return res.redirect("/signin"); }; </code></pre> <p>After logging in my user, I simulated session expiry by deleting the session cookie. Thereafter thru the website I made a PUT '/fantasyteams/123' request to update fantasy team number 123. </p> <p>fantasyteams.update is simply a mongodb / mongoose save operation:</p> <pre><code>exports.update = function(req, res){ var fantasyteam = req.fantasyteam; fantasyteam = _.extend(fantasyteam, req.body); fantasyteam.save(function(err){ res.jsonp(fantasyteam); }); }; </code></pre> <p>As expected, the route handler (app.put ... ) above caught the request, pass it to the auth.requiresLogin middleware to check if the user is logged in. So it turns out the user isn't logged in since I deleted his session cookie. res.redirect is called as expected. However, the website doesn't redirect to the sign in page. I see this in the node.js command logs:</p> <pre><code>PUT /signin 404 328ms </code></pre> <p>What did I do wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload