问题描述
我正在尝试使用passwordjs使用Facebook来注册我的用户。我正在使用mongodb作为数据库,并使用mongoose与之交互。
const userSchema = mongoose.Schema({
email: String,password: String,googleId: String,facebookId: String,secret: [String],});
const User = mongoose.model("users",userSchema);
这是架构。
passport.use(new FacebookStrategy({
clientID: process.env.APP_ID,clientSecret: process.env.APP_SECRET,callbackURL: process.env.CALLBACK_URL,profileFields: ['id','displayName','photos','email']
},function (accesstoken,refreshToken,profile,done) {
//check user table for anyone with a facebook ID of profile.id
console.log(profile);
User.findOne({
facebookId: profile.id
},function (err,user) {
if (err) {
return done(err);
}
//No user was found... so create a new user with values from Facebook (all the profile. stuff)
if (!user) {
user = new User({
name: profile.displayName,email: profile.emails[0].value,username: profile.username,provider: 'facebook',User.findOne({'facebook.id': profile.id } will match because of this next line
facebook: profile._json
});
user.save(function (err) {
if (err) console.log(err);
return done(err,user);
});
} else {
//found user. Return
return done(err,user);
}
});
}
));
这是facebook策略的代码。我可以使用Facebook成功注册,但是无法将用户添加到数据库中。我的Google oauth具有相同的代码,并且似乎可以在Google中使用。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)