I am trying to save a session variable for a user when they login. This works on the computer, but when I try it on an iPad using Safari or Chrome it doesn't save.
Here is where I set up my session:
app.set('trust proxy', 1)
app.use(session({
secret: crypto.randomBytes(20).toString('hex'),
resave: false,
duration: 60 * 60 * 1000,
activeDuration: 10 * 60 * 1000,
saveUninitialized: false,
cookieName: 'session',
cookie: { secure: true }
}))
I use this route to set up the user:
.get('/checkLogin', (req,res) => {
const loginCred = req.query;
db.any('SELECT * FROM users WHERE user_name = $1 AND password = $2 LIMIT 1', [loginCred[0], loginCred[1]])
.then(function (user) {
req.session.user = user;
req.session.save();
res.end(JSON.stringify(user));
})
.catch(function (err) {
throw err;
})
})
When I console log this, it is getting set properly.
Then when I call the session on the return it is not there. I've tried to add the save and that still didn't work. I also added maxage
to the session variable to keep it alive for 3 days and it still didn't work.