【问题标题】:Passportjs: Local strategy is never called and automatically redirects to failureRedirectPassportjs:永远不会调用本地策略并自动重定向到 failureRedirect
【发布时间】:2015-01-09 06:17:23
【问题描述】:

给定以下形式:

<form action="/login" method="post">
      <div>
        <label>Username:</label>
        <input type="text" name="username" />
        <br/>
      </div>
      <div>
        <label>Password:</label>
        <input type="password" name="password" />
      </div>
      <div>
        <input type="submit" value="Submit" />
      </div>
</form>

及快递路线:

app.post('/login', passport.authenticate('local', {
    successRedirect: '/app', 
    failureRedirect: '/login', 
    failureFlash: false 
}));

以及本地策略定义:

passport.use(new LocalStrategy(function(username, password, done) {
    console.log('FTW!');
}));

为什么我从来没有看到“FTW!”在控制台?无论如何,它总是自动将我重定向到 failureRedirect。我无法弄清楚如何调试这个?

【问题讨论】:

    标签: node.js authentication express passport.js


    【解决方案1】:

    我忘了包含快速正文解析器:

    app.use( express.bodyParser());
    

    【讨论】:

    • 我刚要提到你应该检查你的应用中间件:)。下次,您可以依靠这种形式的调用:passport.authenticate("local", function(error, user, info) {...} 来暂停和调试手头的问题。
    猜你喜欢
    • 1970-01-01
    • 2019-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多