路由.js
router.get('/auth/google', passport.authenticate('google', { scope: ['profile', 'email'] }));
router.get('/auth/google/callback', (req, res, next) => {
passport.authenticate('google', {}, (err, token, info) => {
if (info) {
console.log(info)
req.data = info
req.status = 200
req.message = 'User Logged in Succcessfully'
res.redirect('https://www.google.com') // If I comment this it does not show error
next()
}
else {
req.data = null
req.status = 403
return (next(new Error('Unauthorized')))
}
})(req, res, next)
})
我正在使用谷歌策略并且它工作正常,但是如果我使用 res.redirect() 将它重定向到某个 URL,那么它会显示错误“在发送到客户端后无法设置标题”。认证成功后,我想返回信息并将其重定向到网站。任何帮助将不胜感激