Reputation: 293
I'm making a webapp using Backbone.js, Node.js, and Express.js and want to add User functionality (login, logout, profiles, displaying content relevant to that user). I'm planning on using Passport to do the signing in and out. I'm confused though about how the frontend knows which user is logged in for the rest of the session. Do I need to have some variable in the Backbone Router called "loggedInUser" that points to a User model? Or is it the server that needs to know this information and I need to have the variable somewhere on the server? In other words, where should I store the logged in user's info so that I can make requests and responses relevant to the currently logged in user and display information relevant to them? Hopefully my wording is clear. Also, if anyone could provide links to helpful articles on this, that would be great too! Thank you!
Upvotes: 1
Views: 61
Reputation: 1457
Passport already helps you do this. Use passport sessions. The currently logged in user is already available on the server as req.user on every request and the client knows the session information via the session cookies which are handled by passport.
Upvotes: 2