I am currently trying to setup an oauth service for my current project. Being new to all this, I have read many articles on the subject, but I am still missing some pieces.
My environment is:
- servers: node, express, passport
- authentication: local strategy (using my own accounts / passwords)
- I have a database with user/password ( passwords run through bcrypt)
- web interface: react, server accesses through superagent
On my nodejs server, I am using these modules:
- express
- express-session
- express-mysql-session
- passport
- passport-local
- bcrypt
Different parts of the solutions are working: I can create new users, create new sessions, see their content in the express-mysql-session database.
However I am quite confused on the following:
when my web client tries to access protected routes, I don't seem to be getting any cookie in the request. Is it that superagent will not send my passport cookie by default? I read somewhere that in single page apps, jwt might be more appropriate, is that linked to this problem?
despite all I read, I am still confused about deserializeUser. My understanding is that with the passport-local solution, upon access, the web client will send the session cookie, which contains the session Id. Passport will fetch further information concerning this session from database, and then continue to handle the request. Does this session info retrieval happen automatically (in express-mysql-session?)? Or do you have to "manually" do it in deserializeUser (many examples show a
User.findById
call in there)? If you have to do it "manually", it means that you have to access the express-mysql-session db using another connection than the one this module is using?to log out, is req.logout() enough to ensure the session is erased from the session db entirely?