javascript - 在护照谷歌身份验证策略中使用 res.redirect 时出错
问题描述
路由.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,那么它会显示错误“在发送到客户端后无法设置标题”。认证成功后,我想返回信息并将其重定向到网站。任何帮助将不胜感激
解决方案
推荐阅读
- python - How can I find an element looping through a list of divs using Selenium?
- security - ANTLR4 : Does it write anything to local file system while lexing and parsing?
- c++ - Is it possible to use a smart ptr or boost intrusive ptr as the "void* tag" value in a gRPC async server written in C++
- java - JDK 11 PreMaster Secret debugging
- mysql - 使用 mysql 从 Wordpress 网站在 Laravel 应用程序中插入数据
- flutter - Flutter_Swiper 文本覆盖图像
- sql - Oracle父子查询
- sql - 使用 SQL 计算 Fifo
- android - 如何避免本地 Web 应用程序数据被擦除?
- node.js - Nodejs odbc - 插入语句不起作用