I need some help with keystonejs sessions. I'm working on a shopping cart, thus after a customer adds a product to the cart they move onto a check-out page that forces them to sign in as a user. However, when they sign in the session restarts and clears the contents of the cart.
My question: Is there a way to sign in and keep the existing session and then add the user id to the session.
I'm persisting the session to mongodb using connect-mongo.
I have written req.session.cart
to add the products to the session
and use
view.on('post', { action: 'login' }, function (next) {
if (!req.body.email || !req.body.password) {
req.flash('error', { detail: 'Please enter your email and password.' });
return next();
}
var onSuccess = function() {
req.flash('success', { detail: 'Great you are now logged in!' });
res.redirect('/checkout');//redirect on success
}
var onFail = function() {
req.flash('error', { detail: 'Input credentials were incorrect, please try again.' });
return next();
}
keystone.session.signin({ email: req.body.email, password: req.body.password }, req, res, onSuccess, onFail);//
to authorize the user.
Regards
As far as I can tell, user signin with Keystone only appends the
user
property to the request object, and it adds the user's MongoDB id toreq.session.userId
. It doesn't clear the existing session. How are you currently adding to the Keystone session?