Reputation: 33
I am using passport.js and want to return a flash message if username or password are inoccorect setup. All the logic is set up, and it worked before. But i somehow broke the function and its still not working even though i copied the working version 1 by 1. I have flash messaging setup in my application, which works flawlessly for all the other flash messages which don't involve passport.js.
But if i try to log in, my flash message is empty and i receive [object Object]
as a console.log.
Question 1: Is there a way to access all the information that [object Object]
represents?
Question 2: Is there a way to console.log what is being flashed before its displayed? How would i access that part of the sessions?
Route:
router.post('/',
passport.authenticate('local', { successRedirect: '/', failureRedirect: '/login', failureFlash: true }),
function(req, res) {
console.log('Login success.');
});
Passport Code that sends flash message for context:
passport.use(new LocalStrategy(
function(username, password, done) {
User.getUserByUsername(username, function(err, user){
if (err) throw err;
if (!user) {
console.log('A user tried logging in, but username input returned unknown.');
return done(null, false, {message: 'Unknown user.'});
}
User.comparePassword(password, user.password, function(err, isMatch){
if(err) throw err;
if(isMatch) {
return done(null, user);
} else {
console.log('A user tried logging in, but password input returned invalid.');
return done(null, false, {message: 'Invalid password.'});
}
});
});
}
));
Showing the message with handlebars in my view:
{{#if error_msg}}
<div class="alert alert-danger">{{error_msg}}</div>
{{/if}}
{{#if error}}
<div class="alert alert-danger">{{error}}</div>
{{/if}}
(in my older branch that is working, its returning with error_msg -- in my current branch its returning just error with the [object Object] console.log)
Thanks in advance!
Upvotes: 0
Views: 993
Reputation: 33
Fixed issue by removing the handlebars-helpers
library which introduced some issue in regards to flash messaging. (only in combination with how Passport handles flash messages)
Upvotes: 1