CORS problems with Auth0 and React

后端 未结 3 1449
北恋
北恋 2020-12-19 01:48

I am currently trying implement Auth0 in my NodeJS + React App. This tutorial given is really good and helpful, though I have one big problem. Every time I try to login/regi

相关标签:
3条回答
  • 2020-12-19 02:01

    Auth0 needs to know what your allowed origins and callback URLs are for your application. You can configure that in your application's settings in the dashboard: https://manage.auth0.com/#/applications

    0 讨论(0)
  • 2020-12-19 02:01

    Just to elaborate more on the server side since you mentioned you are building a node.js app. I assume you are also using express. To deal with CORS requests you can do the following:

    In your express server file you can set the local host to something other than the client side React app which most likely is running on localhost:3000.

    var port = normalizePort(process.env.PORT || '5000');
    app.set('port', port);
    

    Then install the cors npm package and initialize it in your main express file.

    var app = express();
    app.use(cors());
    

    Then all you have to do is set a proxy in your client side React package.json file.

      },
      "proxy": "http://localhost:5000"
    }
    

    You can then run both your node.js/express server and React app at the same time and use your express server to make requests through the client React with the proxy.

    Hopefully this helps.

    0 讨论(0)
  • 2020-12-19 02:03

    If you are developing locally, you can put the URL you are going to redirect to. For instance, if you are running on your localhost at port 4000, and you want to redirect to your route called /callback, you can put:

    http://localhost:4000/callback
    

    in that field.

    0 讨论(0)
提交回复
热议问题