我正在使用 ExpressJS 和 PassportJS 的 Facebook 策略来尝试对缺少某些属性时应该调用的身份验证回调执行一些条件重定向。
我的用户架构:
var UserSchema = new Schema({
id: ObjectId,
uid: String,
facebookToken: String,
username: String,
password: String,
salt: String,
firstName: String,
lastName: String,
email: String,
birthday: Date,
gender: String,
location: String,
phone: Number,
verifiedPhone: Boolean,
interests: {
culture: Boolean,
food: Boolean,
business: Boolean,
family: Boolean,
learning: Boolean,
sports: Boolean,
movies: Boolean,
music: Boolean,
events: Boolean,
nightlife: Boolean,
health: Boolean,
beauty: Boolean,
fashion: Boolean,
motoring: Boolean,
electronics: Boolean,
groceries: Boolean,
travel: Boolean,
decor: Boolean
},
weeklyNotifcation: Number,
weeklyNotificationSent: Number,
created: {type: Date, default: Date.now}
});
我的回调:
app.get('/auth/facebook/callback', passport.authenticate('facebook', { failureRedirect: '/login' }), function(req, res) {
User.findOne({uid: req.session.uid}, function(err, user) {
if(user.email || user.location || user.phone || user.location == undefined) {
res.redirect('/register');
} else {
res.redirect('/');
}
});
});
调用后数据存储到mongo/auth/facebook
中。我检查数据库是否使用会话并检查它是否未定义,因为它不会返回字段,因为它们没有存储在数据库中。回调失败并且没有返回接收到的数据。
任何帮助将不胜感激。