gpt4 book ai didi

node.js - 错误请求中的身份验证失败 : Missing Credentials

转载 作者:可可西里 更新时间:2023-11-01 09:14:22 25 4
gpt4 key购买 nike

我正在开发 Passport Node.js,Express 登录页面。我是一名 Web 开发人员,但这是我的第一个 Node.js 项目。

我关注了User Authentication with Passport.js

但每次我尝试登录登录页面或注册页面时,我唯一看到的是“错误请求”页面。

我打了个电话回去看看发生了什么:

exports.postRegister = function(req, res) {
login = mongoose.model('login');
login.register(new login({
username: req.body.email
}), req.body.password, function(err, login) {
if (err) {
return res.render('register', {
login: login,
error: err,
title: "S'enregistrer"
});
}
// Something is wrong here
passport.authenticate('local', function(err, user) {
// So let's console log the thing !
console.log(arguments);
})(req, res, function() {
res.redirect('/scene/1');
});
});
};

console.log(参数) 返回:

{
'0': null,
'1': false,
'2': { message: 'Missing credentials' },
'3': 400
}

我检查了我的 MongoDB,用户创建没有问题!

最佳答案

您似乎没有为您的 login 模型指定架构。您需要像这样声明模型:

var Model = mongoose.model('Model', 'modelSchema');

关于node.js - 错误请求中的身份验证失败 : Missing Credentials,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22719028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com