2017-04-05 67 views
1

當我使用PassportJS和passport-google-oauth20與Google登錄時,我的應用程序成功完成請求,但Passport無法識別此消息,而是調用錯誤。PassportJS Google登錄錯誤,但成功

我的代碼如下所示:

router.get('/auth/google/callback', 
    passport.authenticate('google', {failureRedirect: '/login'}), 
    (req, res) => console.log(req), 
    (err, req, res, next) => { 
    console.log('test point 1') 
    console.log(err.stack) 
    return res.status(500).send(err) 
    }) 

輸出看起來是這樣的,這表明該請求沒有失敗,我相信:

test point 1 
undefined 

但是,當我檢查我的瀏覽器,它返回一個500代碼與正確的Google用戶信息,如配置文件圖片和ID。護照不會將它存儲在它應該的req.user變量中。謝謝!

如果它是有用的,我的護照初始化是非常簡單而明確:

// TODO: eventually setup user account system 
passport.serializeUser((user, done) => done(null, user)) 

passport.deserializeUser((obj, done) => done(null, obj)) 

// TODO: eventually use this to associate the users account 
passport.use(new GoogleStrategy({ 
    callbackURL: 'http://localhost:8080/api/v0/auth/google/callback', 
    clientID: 'number-id.apps.googleusercontent.com', 
    clientSecret: 'secrets' 
}, (accessToken, refreshToken, profile, cb) => { 
    cb(profile) 
})) 

我能想到的,這將是我的情況唯一不同的是,我在一個特定的只有use荷蘭國際集團護照一組路線。 (例如API)

回答

0

在此行上:cb(profile)我向回調發送錯誤而不是用戶配置文件。

它應該是這樣的:cb(null, profile)