I have a node.js app hosted on firebase. However where it is hosted should not matter too much here as I am simply trying to store some information in cookies in the /set-cookie
path so it can be accessed in the /user
path. Relevant code in index.ts
here:
// create HTTP server
const app = express();
// use json form parser middleware
app.use(bodyParser.json());
// use query string parser middlware
app.use(bodyParser.urlencoded({ extended: true }));
// cookies
app.use(cookieParser());
app.use(cookieSession({
name : 'session'
, keys : ['abigsecret', 'anothersecret']
, maxAge : 100 * 60 * 60 * 1000
}));
// setting the cookie here
app.get('/set-cookie', (req,res) => {
res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true });
res.send('cookie set...');
}})
// And I would like to access it here
app.get('/user' , (req, res) => {
console.log('cookies: ', req.cookies)
res.render('pages/user')
});
Of course this is not working as intended. since on the console I do not see the cookie I set in /set-cookie
, but rather some client side cookie that was passed to the server. What is the way to set cookies so that I can access it elsewhere?
What I am seeing on the console is this when I navigate to '/user` after '/get-cookie'
info: cookies: { _ga: 'GA1.1.1192529393.1524186034',
ss_cvr: '5407c247-08f6-4b6d-8b27-e623c7788eef|1523239108805|1524436640490|1524443386060|46' }
info:
but I should be seeing some version of : 'rememberme', '1',
correct?