【问题标题】:PassportJS and ExpressJS conditional URL redirectPassportJS 和 ExpressJS 条件 URL 重定向
【发布时间】:2015-01-07 22:01:08
【问题描述】:

我正在使用 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('/');
    }
  });
});

在调用/auth/facebook 之后,数据被存储到mongo 中。我检查数据库是否使用会话并检查它是否未定义,因为它不会返回字段,因为它们没有存储在数据库中。回调失败,没有收到任何数据。

任何帮助将不胜感激。

【问题讨论】:

  • 您解决了这个问题吗?我有同样的问题

标签: javascript node.js express passport.js


【解决方案1】:
if(user.email === undefined || user.location === undefined || user.phone === undefined || user.location === undefined) {

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-31
    • 2012-09-07
    • 2014-01-05
    • 2013-10-27
    • 2021-03-22
    • 1970-01-01
    • 2013-09-21
    • 1970-01-01
    相关资源
    最近更新 更多