StephenGrider / FullstackReactCode

Companion repo to https://www.udemy.com/node-with-react-fullstack-web-development
1.39k stars 1.17k forks source link

After loggin to app it redirect to localhost:5000/surveys #65

Open ossmate opened 4 years ago

ossmate commented 4 years ago

After loggin to app it redirect to localhost:5000/surveys instead of localhost:3000/surveys

authRoutes.js

  app.get(
    '/auth/google/callback',
    passport.authenticate('google'),
    (req, res) => {
      res.redirect('/surveys');
    }
  );

setupProxy.js -> instead of proxy in package.json

const { createProxyMiddleware } = require('http-proxy-middleware');

module.exports = function(app) {
  app.use(
    '/auth/google',
    createProxyMiddleware({
      target: 'http://localhost:5000',
      changeOrigin: true,
    })
  );

  app.use(
    '/api/*',
    createProxyMiddleware({
      target: 'http://localhost:5000',
      changeOrigin: true,
    })
  );
};

console identification URI http://localhost:5000 http://localhost:3000

autorizated URI http://localhost:5000/auth/google/callback http://localhost:3000/auth/google/callback

I just simply get error Cannot GET /surveys and browser URL is http://localhost:5000/surveys

Miquelllabres commented 4 years ago

I am having the same issue, same code and also using setupProxy.js

Miquelllabres commented 4 years ago

I did remove the changeOrigin and it works. cheers

ossmate commented 4 years ago

I did remove the changeOrigin and it works. cheers

hmm, true we will see if it's worky only for 5 min or more

afrancht commented 4 years ago

I'm having the same issue. For some reason it will not redirect back even after taking out change origin. @Miquelllabres would you mind sharing your code.

Devanshi-123 commented 4 years ago

I'm also having the same issue.It would be great if anyone could suggest what can be done to solve this. Removing change Origin didn't worked out for me.

valeriia-bohachevska commented 4 years ago

Please, try this:

const proxy = require("http-proxy-middleware");

module.exports = function (app) {
  app.use(proxy("/auth/google", { target: "http://localhost:5000/" }));
  app.use(proxy("/api/*", { target: "http://localhost:5000/" }));
};
IROCX commented 4 years ago

In your Google auth profile change callback URL to http://localhost:3000/auth/google/callback