javascript - Passport Local strategy session using express in Node.js -


i'm newbie in node.js , used passport-local strategy login session. set things in web app, i'm having big problem session.

i tried multiple users can login web app @ same time, there problem. 1 of users(ex. username paul) log in first, , user(chris) log in after, paul's view of web app changed chris' view.

i'm not sure guys understand mean here 1 of code in node.js

app.get('/location', isloggedin, function(req, res){   var user_temp = {user: ''};   user_temp.user = global_username;   res.render('location/index1', user_temp); }); 

and below code passport local-strategy

var localstrategy = require('passport-local').strategy; passport.use('local-login',   new localstrategy({       usernamefield : 'email',       passwordfield : 'password',       passreqtocallback : true     },     function(req, email, password, done) {       user.findone({ 'email' :  email }, function(err, user) {         if (err) return done(err);         if (!user){             req.flash("email", req.body.email);             return done(null, false, req.flash('loginerror', 'no user found.'));         }         if (!user.authenticate(password)){             req.flash("email", req.body.email);             return done(null, false, req.flash('loginerror', 'password not match.'));         }         var email_address = req.body.email;         username_tmp = email_address;         var username = email_address.substring(0, email_address.lastindexof("@"));         global_username = username;         pass = req.body.password;         return done(null, user);       });     }   ) ); 

i think problem because of global_username, paul can see chris' view of location. however, don't know how user variable , put ejs each users.

can me out here....?

thanks in advance!

p.s. if asked confused, can edit question again , explain more...

you can't use globals, overwritten each request result in issue you're describing.

instead, if have set passport , express-session correctly, passport provide user data each (authenticated) request through req.user:

app.get('/location', isloggedin, function(req, res) {   res.render('location/index1', { user : req.user }); }); 

you can take @ the passport-local example application idea on how connected.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -