CORS problems with Auth0 and React

大憨熊 提交于 2019-11-29 09:50:38
Kassandra Perch

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.

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!