try {
let sessionObj = session({
secret: process.env.SESSION_SECRET,
store: new MongoStore({
mongooseConnection: global.db,
collection: 'user_sessions'
}),
cookie: {
maxAge: (60 * 60) * 1000, // 1 hour - milliseconds
},
rolling: true, // resets the cookie max age on each request
resave: false,
saveUninitialized: true
});
app.use(sessionObj);
} catch (err) {
console.log('Error: ', err);
return false;
}
After successfully logging in, I can do a "console.log(req.session); async auth(email, password) {
const isDev = (process.env.ENV == 'local' || process.env.ENV == 'dev');
let match = {
email: email,
active: true
};
try {
let user = await this.loadUser(match);
// validate the password hash
if (!isDev) {
await this.checkPasswordHash(password, user.password);
}
return this.success(user);
} catch (err) {
console.log('Error: ', err);
return this.error(err);
}
}
router.post('/login/auth', async (req, res) => {
if (typeof req.body.email == 'undefined' || typeof req.body.password == 'undefined') {
flash.add(req, 'Please enter a valid email address and password before trying again.', 'danger');
return res.redirect('/login');
}
let resp = await user.auth(req.body.email, req.body.password);
if (resp.error) {
flash.add(req, 'The provided email address and password combination is invalid. Please try again. If you need further assistance, please call 855.581.9910.', 'danger');
return res.redirect('/login');
}
req.session.user = resp.data;
await user.lastLogin();//Update lastLogin date
let redirect = (req.body.redirect != '') ? req.body.redirect : '/';
res.redirect(redirect);
});
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE