LinkedIN OAuthlogin麻烦Nodejs

我正在使用LinkedIn OAuth和护照进行login。无论什么原因,我第一次尝试login时,它会在没有login的情况下路由到主页。然而,第二次login正确。 什么可能导致这个问题? LinkedIn或护照?

这是获取path:

router.get('/auth/linkedin/callback', passport.authenticate('linkedin', {failureRedirect: '/', failureFlash:true}), function (req, res, next) { User.findOne({_id: req.user._id}, function (err, user) { if (err) { return next(err); res.redirect("/") } user.last_login = moment(); user.save() return res.redirect('/profile/' + user.username); }); }); 

然后护照链接在:

 passport.use(new LinkedInStrategy({ clientID: config.linkedin.consumerKey, clientSecret: config.linkedin.consumerSecret, callbackURL: config.linkedin.callbackURL, state: true, scope: ['r_basicprofile', 'r_emailaddress']}, function (token, refreshToken, profile, done) {