Node.js 登录后响应express paspport和google身份验证重定向
我正在尝试在我的react express应用程序中使用google身份验证。我在我的GoogleAuth20客户端ID上设置了两个回调重定向URI,如附件所示。我将react proxy配置为在setupProxy.js中向Node.js 登录后响应express paspport和google身份验证重定向,node.js,reactjs,express,authentication,passport.js,Node.js,Reactjs,Express,Authentication,Passport.js,我正在尝试在我的react express应用程序中使用google身份验证。我在我的GoogleAuth20客户端ID上设置了两个回调重定向URI,如附件所示。我将react proxy配置为在setupProxy.js中向/auth/google或/api/*发出请求时重定向到服务器,因为我使用的是creat react app v2。应用程序可以从客户端重定向,谷歌可以验证登录用户,但谷歌会继续重定向到http://localhost:5000/auth/google/callback在用
/auth/google
或/api/*
发出请求时重定向到服务器,因为我使用的是creat react app v2。应用程序可以从客户端重定向,谷歌可以验证登录用户,但谷歌会继续重定向到http://localhost:5000/auth/google/callback
在用户登录后。我想重定向到http://localhost:3000/auth/google/callback
即用户成功登录后的我的客户端uri。例如localhost:3000/调查
而不是localhost:5000/调查
我的setupProxy.js文件内容
const { createProxyMiddleware } = require('http-proxy-middleware')
module.exports = function (app) {
app.use(
['/auth/google', '/api/*'],
createProxyMiddleware({
target: 'http://localhost:5000',
changeOrigin: true
})
)
}
我的护照和特快专递经办人
const passport = require('passport')
module.exports = app => {
app.get(
'/auth/google',
passport.authenticate('google', {
scope: ['profile', 'email']
})
)
app.get(
'/auth/google/callback',
passport.authenticate('google'),
(req, res) => {
res.redirect('/surveys')
}
)
app.get('/api/logout', (req, res) => {
req.logout()
res.redirect('/')
})
app.get('/api/current_user', (req, res) => {
res.send(req.user)
})
}
我的google auth20客户端ID设置
授权重定向URI
如附件所示。您只需删除在
createProxyMiddleware
函数中传递的选项对象中的行changeOrigin:true
。您解决了吗?