Reputation: 6899
I am trying to display errorMessages
to the user once after they fail registration. If the registration page is visited again the errorMessages
array will not be displayed. For some reason req.session.errorMessages
is being displayed on every request to the registration page.
module.exports.registration = function(req,res){
if(Array.isArray(req.session.errorMessages) && req.session.errorMessages.length > 0)
res.locals.errorMessages = req.session.errorMessages;
else
res.locals.errorMessages = [];
res.render('registration',{
});
//This line does not seem to reset the array after the response has been rendered
req.session.errorMessages = [];
};
Upvotes: 1
Views: 251
Reputation: 33409
Move it above the render
call. It seems that you can't change req
or res
anymore after returning data to the user.
Upvotes: 1