简体   繁体   English

Flash消息返回[object Object](节点Express Passport)

[英]flash message returning [object Object] (Node Express Passport)

I am using passport.js and want to return a flash message if username or password are inoccorect setup. 我正在使用passport.js,如果用户名或密码设置不正确,则想返回一条简短消息。 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. 但是我以某种方式破坏了该功能,即使我按1拷贝了工作版本,该功能仍然无法正常工作。我的应用程序中具有Flash消息传递设置,该设置对于所有其他不涉及passport.js的Flash消息都可以正常使用。

But if i try to log in, my flash message is empty and i receive [object Object] as a console.log. 但是,如果我尝试登录,则刷新消息为空,并且我收到console.log的[object Object]

Question 1 : Is there a way to access all the information that [object Object] represents? 问题1 :是否可以访问[object Object]代表的所有信息?

Question 2 : Is there a way to console.log what is being flashed before its displayed? 问题2 :有没有办法console.log在显示之前刷新什么? 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) (在较旧的分支中,它以error_msg返回-在当前分支中,[object Object] console.log仅返回错误)

Thanks in advance! 提前致谢!

Fixed issue by removing the handlebars-helpers library which introduced some issue in regards to flash messaging. 通过删除handlebars-helpers库修复了问题,该库引入了有关Flash消息传递的一些问题。 (only in combination with how Passport handles flash messages) (仅结合Passport处理Flash消息的方式)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM