我在反應和節點上做了usewr註冊登錄。我的註冊路線正在工作,用戶保存在mongo中,但是登錄路線不起作用?用戶註冊使用Mongo和NodeJs不能正常工作
簽到組件: -
signIn(){
axios.post('/tasks/signin', {
email: this.state.email,
password: this.state.password,
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
}
航線有: -
Router.post('/signin', (req, res) => {
var User = new db1();
User.findOne({ email: req.body.email , password: req.body.password
}, function(err, user) {
console.log(user);
if(err) return next(err);
if(!user) return res.send('Not logged in!');
return res.send('Logged In!');
});
});
錯誤:
User.findOne is not a functionand i am getting 500 status.
請幫我在哪裏錯了。
什麼是db1?您是使用Mongoose還是其他框架連接到Mongo? –
@MarkS。 Db1是model const db1 = require('../ models/users'); –