spent a couple of days attempting to set up a proxy for my react app to my express backend where I am using passportjs for gooogle social auth.
react dev server on PORT 3000 express server on PORT 5000
When I click on the button, it reloads the page, but does not start the passportJS google auth process (i.e. does not redirect to the oauth2 flow).
<Button href='/auth/google'> Link Button </Button>
- curl is properly proxying the calls from port 3000 to 5000
- PassportJS process works properly when I go directly to the express server endpoint I created here: http://localhost:5000/auth/google
Key code pieces are below that should allow proxy to work from react frontend to express passportJS Oauth2 flow.
package.json
"proxy": "http://localhost:5000"
app.js
<a href="auth/google/" target="">
<Button> Link Button </Button>
</a>
server.js
app.get('/auth/google',
passport.authenticate('google', { scope: ['https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile',
'openid'] }),
);
setupProxy.js
const proxy = require("http-proxy-middleware");
module.exports = function(app) {
app.use(proxy('/auth', { target: 'http://localhost:5000/' }));
};