Quesurfin Quesurfin - 1 year ago 78
Node.js Question

Express redirects to wrong view after passport authentication

I'm having quite the time figuring out why the URL is updating but it goes to the wrong view.

When a user is authenticated with passport, the URL updates to my code (/clients) but the view goes back to the homepage view.

After the user is authenticated, i'd like them to be redirected to my angular app.

folder structure

-client (ng app)
index.jade (angular app index)
index.jade (express index)


app.set('view engine', 'jade');
app.set('views', config.rootPath + '/server/views/');


login: function(req, res, next) {
var auth = passport.authenticate('local', function(err, user) {
if (err) return next(err);
if (!user) {
req.session.error = 'Invalid Username or Password!';

req.logIn(user, function(err) {
if (err) return next(err);
auth(req, res, next);


var auth = require('./auth'),
controllers = require('../controllers');

module.exports = function(app) {
app.get('/register', controllers.users.getRegister);
app.post('/register', controllers.users.createUser);

app.post('/login', auth.login);
app.get('/logout', auth.logout);
app.get('/login', controllers.users.getLogin);

app.get('/', function (req, res) {
res.render('index', {currentUser: req.user});

app.get('*', function (req, res) {
res.render('index', {currentUser: req.user});

If anyone can point me in the right direction, i'd greatly appreciate it.

Answer Source

Add a route

   app.get('/client', function (req, res) {
     res.render('client/index', {currentUser: req.session.user});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download