在弄清楚如何通过我的 Facebook 登录访问当前用户时遇到一些问题。我正在使用 PassportJS、Node、express。我认为我的“用户”没有保持登录状态,但我无法检查。我将上传我所拥有的内容,并感谢所有查看它的人 - 真的很感激。
路由.js
app.get('/auth/facebook', passport.authenticate('facebook', { scope : ['email', 'public_profile', 'user_friends'] }));
// handle the callback after facebook has authenticated the user
app.get('/auth/facebook/callback',
passport.authenticate('facebook', {
successRedirect : '/profile',
failureRedirect : '/'
}));
// route for logging out
app.get('/logout', function(req, res) {
req.logout();
res.redirect('/');
});
};
function isLoggedIn(req, res, next) {
// if user is authenticated in the session, carry on
if (req.isAuthenticated())
return next();
// if they aren't redirect them to the home page
res.redirect('/');
} …Run Code Online (Sandbox Code Playgroud)