[Update] Question now contains necessary details because of which the author was successful at finding a solution and hence should be reopened for answers.
Question in the title. Is there a way to use connect-flash in the back end (express) so that messages are accessible in the front end react app?
My passport local strategy, I am using a sqlite db:
passport.use(
new LocalStrategy({ usernameField: 'name' },
(name, password, done) => {
//Match user
db.get(`SELECT * FROM Users WHERE name = '${name}'`, (err, user) => {
if(err) throw err;
if(!user) {
return done(null, false, { msg : 'name not registered' });
}
//Match password
bcrypt.compare(password, user.password, (err, isMatch) => {
if(err) throw Error;
if(isMatch) {
done(null, user);
} else {
done(null, false, { msg : 'Password incorrect' })
}
});
})
})
);
and my /login route:
//Login Handle
usersRouter.post('/login', passport.authenticate('local'), (req, res ) => {
res.json('Successfully authenticated.')
}
);
I read that I can add options to this route in an object including
{
failureFlash: true
}
but I am just don't understand how to access the messages (stored in req.flash ?) in my react front end.