How to redirect the user back to the same page after authentication?
<p>I am new to this whole node thing, and password is quite intriguing and seems to quite work for many of the authentications, so it looked cool. </p>

<p>Scenario: I wanted to say, /profile to proceed, only when user is logged in. </p>

<p>Here is the route I made,</p>

<pre><code>var express = require('express');
var router = express.Router();
</code></pre>

<p>the rest is in the file called router/index.js </p>

<pre><code>var passport = require('passport');
var ensureLoggedIn = require('connect-ensure-login').ensureLoggedIn;


router.post('/login', passport.authenticate('login', {
    successRedirect: '/home',
    failureRedirect: '/',
    failureFlash : true  
}));


router.get('/profile', ensureLoggedIn('/'), function(req, res){
    res.json({ user: req.user });
});
</code></pre>

<p>So, based on my understanding and willingness, when I did GET /profile, it had to go to login page, and then redirect to GET /profile. Unfortunately, since the login page is supposed to return home, it does so. </p>

<p>connect-ensure-login is what I expected to solve the problem, but it hasn't. How do I make it work as I needed?</p>