I currently have 2 different routers set up in my application:
Router 1
app.post('/consultations', function(req, res) {
req.session.name = 'administrator';
console.log('test', req.session.name); // the session is properly saved here
});
Router 2
router.get('/', function(req, res) {
console.log('retrieve session', req.session); // returns undefined
}
I am wondering how I can access and retrieve the session data from both routers.
EDIT: I have created a middleware for this purpose
function mymiddleware(req, res, next) {
req.session.name = 'MyNAME';
}
When I try to utilize the middleware on each router route:
app.get('/myroute1', mymiddleware, (req, res) => {
console.log(req.session.name);
}
The output never gets logged. Similarly,
app.get('/myroute2', mymiddleware, (req, res) => {
console.log(req.session.name);
}