javascript - handling username and pass in session in nodejs-express -



javascript - handling username and pass in session in nodejs-express -

i have nodejs-express app running , newbie @ this.

in home page ('/') have following:

app.get('/', function(req, res){ // check if user's credentials saved in cookie // if (req.cookies.user == undefined || req.cookies.pass == undefined){ res.render('login', { title: 'krishimoney' }); } else{ // effort automatic login // am.autologin(req.cookies.user, req.cookies.pass, function(o){ if (o != null){ req.session.user = o; res.redirect('/home'); } else{ res.render('login', { title: 'krishimoney' }); } }); } });

now when print req.cookies.user gives me username.anyhow, somwhere downwards routes have admin route:

app.get('/admin', function(req, res){ var admin_username = 'admin' var admin_password = 'nansat' console.log(req.cookies.user); //if (req.session.user != admin_username && req.session.pass != admin_password) res.redirect('404'); (res.render('admin_login', {title : 'admin page'})); });

here when type same command req.cookies.user, gives me undefined. how mantain user , pass through out routes?

javascript node.js session express session-cookies

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -