【发布时间】:2019-01-11 09:38:07
【问题描述】:
今天我遇到了一个全新的问题! 首先,我有两个重要文件:
passport.js 本地注册部分
passport.use('local-signup', new LocalStrategy({
usernameField: 'email',
passwordField: 'password',
passReqToCallback: true // allows us to pass back the entire request to the callback
},
function(req, res) {
var password = req.body.password;
var email = req.body.email;
var generateHash = function(password) {
return bCrypt.hashSync(password, bCrypt.genSaltSync(8), null);
};
User.find({
where: {
email: email
}
}).then(function(user) {
if (user) {
return res.json('That email is already taken');
} else {
var userPassword = generateHash(password);
var data = {
username: req.body.username,
name: req.body.name,
firstname: req.body.firstname,
email: req.body.email,
location: req.body.location,
type: req.body.type,
password: userPassword
};
db.users.create({
username: data.username,
name: data.name,
firstname: data.firstname,
email: data.email,
location: data.location,
type: data.type,
password: data.password
}).then(newUser => {
return res.json(newUser)
});
}
});
}
));
我正在做一个身份验证部分。首先,我想创建一个帐户并为其使用护照:注册。
我还使用 Sequelize 来管理我的数据模型。 但是当我用 POST 请求调用这个 localStrategy 时(我的身体在邮递员中一切正常)我有这个错误:
Unhandled reject TypeError: res.json is not a function就行了 返回 res.json(newUser)
有人可以帮帮我吗? 请注意,由于 passReqToCallback,done() 不起作用(但我需要这个来获取我的密码和电子邮件)
【问题讨论】:
-
你在用 expressjs 吗?
-
是的,对不起,我忘了告诉
标签: node.js sequelize.js passport.js