google-oathlogin后挂起的node.js / express /护照

我正在尝试学习node.js,并且在使用google oauth做快速login存储cookie时感到头疼。 我正在使用mongodb,用户得到保存没有问题。

我可以login就好了,但是当我设置cookie baaaam。 但是在控制台上没有错误。

如果我尝试使用Cookie会话设置cookie,并且表示应用程序挂起,我甚至不能访问任何path“/”甚至是“/注销”。 我只能访问他们,如果我清除浏览器上的cookies。 我被困在这一点上。

这是我的app.js

app.use( cookieSession({ maxAge: 30 * 24 * 60 * 60 * 1000, keys: [keys.cookieSession] }) ); app.use(passport.initialize()); app.use(passport.session()); 

我的路线

 app.get('/auth/google', passport.authenticate('google', { scope: ['profile', 'email'] }) ); app.get('/auth/google/callback', passport.authenticate('google')); app.get('/api/logout', (req, res) => { req.logout(); res.send(req.user); }); 

和我的passport.js

 passport.serializeUser((user, done) => { done(null, user.id); }); passport.deserializeUser((id, done) => { User.findById(id).then(user => { done(err, user); }); }); passport.use( new GoogleStrategy({ clientID: keys.googleClientID, clientSecret: keys.googleClientSecret, callbackURL: '/auth/google/callback' }, (accessToken, refreshToken, profile, done) => { User.findOne({ googleId: profile.id }).then((existingUser) => { if (existingUser) { // don't create a new user done(null, existingUser); } else { // create a new user new User ({ googleId: profile.id }).save() .then(user => (null, user)); } }) } )); 

所以我能够得到这个工作,但我想知道什么是错的。

我改变了这一点,它的工作,任何人都有线索?

 passport.deserializeUser((id, done) => { User.findById(id).then(user => { done(err, user); }); }); 

 passport.deserializeUser((id, done) => { User.findById(id, (err, user) => { done(err, user); }); });