【问题标题】:HTTPS with Passport-Local-mongoose in HerokuHeroku 中带有 Passport-Local-mongoose 的 HTTPS
【发布时间】:2018-04-05 01:56:57
【问题描述】:

有人遇到heroku中的错误吗?我有 MissingUsernameError 当我使用 postman 到 https 链接注册用户时,当我在本地使用 HTTP 但使用远程数据库(mLab)时它工作正常,有人遇到同样的问题吗?

我正在使用这些 npm 包

"body-parser": "~1.18.2",
"cookie-parser": "~1.4.3",
"debug": "~2.6.9",
"dotenv": "^4.0.0",
"ejs": "^2.5.7",
"express": "~4.15.5",
"express-jwt": "^5.3.0",
"express-session": "^1.15.6",
"heroku-ssl-redirect": "0.0.4",
"jsonwebtoken": "^8.1.1",
"mongoose": "^4.12.5",
"morgan": "~1.9.0",
"multer": "^1.3.0",
"passport": "^0.4.0",
"passport-local": "^1.0.0",
"passport-local-mongoose": "^4.4.0",
"path": "^0.12.7",
"randomstring": "^1.1.5",
"serve-favicon": "~2.4.5"

//register user
router.post('/register', (req, res) => {
var userAccount = new Account({
    username: req.body.username,
    email: req.body.email,
    company: req.body.company,
    active: true
});

Account.register(userAccount,req.body.password, function (err, account) {
    if(err){
        res.json({
            success: false,
            message: 'registration of the user failed',
            error: err 
        });
    }else{
        passport.authenticate('local')(req, res, function () {
            req.session.save(function (err) {
                if (err) {
                    res.json({
                        success: false,
                        message: 'registration of the user failed',
                        error: err
                    });
                }else{
                    res.json({
                        success: true,
                        message: 'user registered successfully'
                    });
                }
            });
        });
        } 
    }
);

});

我的回复如下。

{
"success": false,
"message": "registration of the user failed",
"error": {
    "name": "MissingUsernameError",
    "message": "No username was given"
}

}

【问题讨论】:

  • http 在本地工作得很好,因为我能够使用远程数据库(mlab)注册用户。我 100% 确定通过了用户名和密码参数并且它们是正确的,因为它适用于 HTTP。

标签: node.js mongodb heroku passport.js passport-local


【解决方案1】:
username: req.body.username,

应该是

name: req.body.username,

【讨论】:

    猜你喜欢
    • 2021-10-13
    • 2013-07-23
    • 1970-01-01
    • 2022-07-30
    • 2017-09-25
    • 2021-08-15
    • 2018-11-07
    • 2018-12-13
    • 2014-07-21
    相关资源
    最近更新 更多