Question

How do I set up passport.js so that if I have two different users login in, it would be two distinct accounts. Right now I am running into a weird bug in which one user logs in. If a second user logs in, and the first user refreshes the page, the first user becomes the second user...

Was it helpful?

Solution

It's hard to say without code but you've probably got a problem in your verify callback. The verify callback is located in the place where you initialize your Strategy. You're probably assigning all authenticated user ids to the same user on the server.

passport.use(new LocalStrategy(
  function(username, password, done) {
    // The problem is probably in here
  }
));

The second most likely place is deserializeUser

passport.deserializeUser(function(id, done) {
  // could be here, too
});

Last place to check would probably be serializeUser, the companion to the above method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top