0

我正在使用 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中。我检查数据库是否使用会话并检查它是否未定义,因为它不会返回字段,因为它们没有存储在数据库中。回调失败并且没有返回接收到的数据。

任何帮助将不胜感激。

4

1 回答 1

1
if(user.email === undefined || user.location === undefined || user.phone === undefined || user.location === undefined) {

可能是你的意思。此外,您可能应该检查err变量以查看是否有错误。

于 2012-11-20T19:58:35.733 回答