Saturday 7 October 2017

Client-sessions not saving cookies

I am using an express setup and have installed a module called 'client-sessions' through npm in an attempt to save cookies to the user's browser when they log in. I am not using passport, I already have login authentication set up through my API.To my understanding, this is a 3-step process:1) Set middleware for client-sessions app.use(session({cookieName: 'session', secret: 'mysecret', duration: 30601000, activeDuration: 15601000}));2) Once a user is logged in, store the cookie in the user's browser with the following: req.session.user = user; // 'user' being the user object of the account stored in the API3) Then, every page redirect thereafter will check if req.session.user exists and contains valid account information.The first two steps seem to be working fine; when logging req.session to the console after the middleware is set, I am getting a blank object(i.e. {}) - I assume this means the middleware works correctly. Then after a user successfully logs in and eq.session.user is set, logging req.session successfully gives me the user object (so, no longer a blank object).However, when I refresh the page, req.session is blank again, and no longer contains the user object. For some reason, the cookie just isn't saving to the user's browser.According to this documentation (http://ift.tt/1wAgSin), setting req.session = cookieObject is enough to save a cookie to the user's browser, however it does not appear to be doing so.Any help?

Submitted October 07, 2017 at 06:29PM by pwnju1ce

No comments:

Post a Comment