Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 登录后响应express paspport和google身份验证重定向_Node.js_Reactjs_Express_Authentication_Passport.js - Fatal编程技术网

Node.js 登录后响应express paspport和google身份验证重定向

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在用

我正在尝试在我的react express应用程序中使用google身份验证。我在我的GoogleAuth20客户端ID上设置了两个回调重定向URI,如附件所示。我将react proxy配置为在setupProxy.js中向
/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

您解决了吗?