Express, Handlebars show flash messages Express, Handlebars show flash messages express express

Express, Handlebars show flash messages


I solved it btw like so:...

if (!user) {            return done(null, false, {                message: 'The email you entered is incorrect'            });

...That encodes the message in JSON.Then in routes I got:

app.get('/sign-in', function(req, res) {        res.render("signin.handlebars", {layout: 'users.handlebars', action: 'Sign in', ***error: req.flash('error')***,                    csrf: 'CSRF token goes here' });    })

Then in my handlebars template:

{{#if error}}    <div class="alert alert-danger">{{error}}</div>{{/if}}


You need to add a global variable in your index.js

app.use((req, res, next)=>{  app.locals.success = req.flash('success')  next();});

Then in your route you add the message

req.flash("success", "Your message");

Finally you .hbs

{{#if success}}{{success}}{{/if}}