一切似乎都有效。Parse.com的请求检查用户是否存在并创建或检索它。我有两个主要问题。首先,当deserializeUser
函数被调用时,它返回 20 个相同的用户,并且findUser
函数应该返回这 20 个用户。另外,我无法访问req.user
passport.serializeUser(function(user, done) {
done(null, user.objectId);
});
passport.deserializeUser(function(uid, done) {
console.log(uid)
// This outputs the ObjectId 20 TIMES!! ??
Parse.findUser(uid,function(error,user){
done(null, user);
})
});
// CONFIGURATION
app.configure(function() {
app.use(express.bodyParser()); //read
app.use(express.cookieParser()); //read
app.use(express.session({ secret: process.env.SESSION_SECRET || 'abcde' }));
app.use(passport.initialize());
app.use(passport.session());
app.use(app.router);
app.use(express.static(__dirname + '/static'))
});
passport.use(new FacebookStrategy({
clientID: process.env.FACEBOOK_APP_ID || 'app_id',
clientSecret: process.env.FACEBOOK_SECRET || 'fb_secret',
callbackURL: "http://localhost:5000/auth/facebook/callback"
},
function(accessToken, refreshToken, profile, done) {
process.nextTick(function() {
_parse.user(accessToken, profile,function(parseUser){
//this returns the user.....
return done(null, parseUser);
})
})
})
)
app.get('/auth/facebook',
passport.authenticate('facebook',{scope:'email'}),
function(req, res){
// The request will be redirected to Facebook ....
});
app.get('/auth/facebook/callback',
passport.authenticate('facebook', { failureRedirect: '/login' }),
function(req, res) {
console.log(req.user)
// this works! ...
res.redirect('/browse');
});
app.get('/browse',function(req,res){
console.log(req.user)
// this is works too ...
res.render('browse.jade',{title:'Browse',classes:'browse'})
})
app.get('/logout', function(req, res){
req.logout();
res.redirect('/login');
});