I am trying to validate the values in the controller and send the flash error message to the EJS view file in Sailsjs Framework.
I am getting the following error message:
if(flash && flash.err) {
>> flash is not defined in ejs file.
I have added the flash policy in config/policies.js
'*': 'flash',
And this is how I am redirecting to the error view..
var usernamePasswordRequiredError = [{
name: 'usernamePasswordRequired',
message: 'You must enter both a username and password.'
}]
req.session.flash = {
err: usernamePasswordRequiredError
}
res.redirect("/user/loginpage");
return;
Flash.js content
Policy File:
module.exports = function(req, res, next) {
res.locals.flash = {};
if(!req.session.flash) return next();
res.locals.flash = _.clone(req.session.flash);
req.session.flash = {};
next();
};
Help me to resolve this Flash is not defined error in view files.