I would do something like this on node.js:
var userlogin = function () {
var req = this.request
,res = this.response
,login = req.body
,username = login.username
,password = login.password;
if(username === 'tester' && password === '12345'){
req.session.user_id = xxxxxx;
res.redirect('/');
}else{
res.redirect('/login');
}
}
var checkAuth = function(fn_auth, fn_unauth){
var req = this.request
,res = this.response
,unauthCallback;
if(req.session.user_id){
fn_auth(); //execute fn_auth if user is logged in. callback can be set to redirect to root path '/'
}else{
fn_unauth(); //execute fn_unauth calback which bring user to login path '/login'
}
}
}
Basically just redirect when the user is already logged in. Hope that helps?