Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

express - Why I can't send flash messages in passport.js?

I had a problem previously with passport authentication but solved it and now when I login with right credentials, flash messages don't work, but when I log with wrong credentials, they work. What could it be?


router.post('/login', passport.authenticate('local', { failureFlash: true, successFlash: true, failureRedirect: '/login' , successRedirect: "/campgrounds"}), (req, res) => {
    req.flash('success', 'welcome back!');
});

module.exports = router;

And a part of passport code

app.use(flash());
app.use(passport.initialize());
app.use(passport.session());
passport.use(new localStrategy(User.authenticate()));


passport.serializeUser(function(user, done) {
    done(null, user.id); 
});

passport.deserializeUser(function(id, done) {
    User.findById(id, function(err, user) {
        done(err, user);
    });
})
question from:https://stackoverflow.com/questions/65924540/why-i-cant-send-flash-messages-in-passport-js

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...