Паспорт Facebook всегда перенаправлять - PullRequest
0 голосов
/ 31 мая 2018

Прежде всего, я хотел бы поблагодарить всех, кто прочитал бы мой постЗдесь проблема:Я использую паспорт facebook auth от jaredhanson, но как только мне наконец удалось войти в систему, и теперь каждый раз, когда я захожу в / auth / facebook (даже на моем смартфоне), он всегда перенаправляет на / auth / facebook / callback? Code = XYC ... тогда какследует перенаправлять на страницу входа в Facebook каждый раз.Вот мой код:

passport.use(new FacebookStrategy(
  {
    clientID: config.facebook.oauth.clientId,
    clientSecret: config.facebook.oauth.clientSecret,
    callbackURL: config.facebook.oauth.callbackURL,
    profileFields: config.facebook.oauth.profileFields,
  },
  ((accessToken, refreshToken, profile, done) => {
    User.findOrCreateFacebook(profile, (err, user) => {
      return done(err, user);
    });
  }),
));
router.get('', passport.authenticate('facebook'));
router.get(
  '/callback',
  passport.authenticate('facebook', {
    failureRedirect: '/facebook',
  }), (req, res) => {
    const profile = {
      id: req.user._id, //eslint-disable-line
      firstname: req.user.FName,
      lastname: req.user.LName,
      email: req.user.email,
      profilPic: req.user.photoProfil,
    };
    return res.status(200).json({
      success: true,
      token: signToken(profile),
    });
  },
);
UserSchema.statics.findOrCreateFacebook = function findOrCreateFacebook(profile, callback) {
  const user = new this();
  this.findOne({ facebookId: profile.id }, (err, result) => {
    // Be careful of the case duplicate mail
    if (!result) {
      user.email = profile._json.email;
      user.facebookId = profile._json.id;
      user.LName = profile._json.last_name;
      user.gender = profile._json.gender;
      user.FName = profile._json.first_name;
      user.photoProfil = profile.photos.length > 0 ? profile.photos[0].value : null;
      user.password = 'facebook'; // useless thing..
      user.save((error) => {
        callback(error, user);
      });
    } else {
      callback(err, result);
    }
  });
};
  passport.serializeUser((user, done) => {
    done(null, user);
  });
  passport.deserializeUser((user, done) => {
    done(null, user);
  });
  app.use(passport.initialize());
  app.use(passport.session());

Честно говоря, я схожу с ума: (

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...