Auth0 和 React 的 CORS 问题 [英] CORS problems with Auth0 and React

查看:34
本文介绍了Auth0 和 React 的 CORS 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试在我的 NodeJS + React 应用程序中实现 Auth0.尽管我有一个大问题,但给出的本教程非常好且很有帮助.每次我尝试通过 Auth0 登录/注册时,我都会收到

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/register via Auth0 I get

XMLHttpRequest 无法加载https://XYZ.eu.auth0.com/usernamepassword/login.对预检的响应请求未通过访问控制检查:否请求中存在Access-Control-Allow-Origin"标头资源.Origin 'http://localhost:3000' 因此是不允许的使用权.对预检请求的响应未通过访问控制检查: 'Access-Control-Allow-Origin' 标头不存在于请求的资源.Origin 'http://localhost:3000' 因此不是允许访问.

XMLHttpRequest cannot load https://XYZ.eu.auth0.com/usernamepassword/login. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.

所以我粗略地理解了这意味着什么.但我只是不知道在哪里设置允许此请求到 Auth0 所需的选项.在服务器端?在浏览器代码中?

So I have a rough understanding what that means. But I just don't know where to set the needed options to allow this request to Auth0. On the Server side? In the Browser code?

最好的问候

正如 Rodrigo López Dato 指出的那样,我可以在我的应用程序中编写 Origins:https://manage.auth0.com/#/applications

as Rodrigo López Dato pointed out, I can write Origins in my app here: https://manage.auth0.com/#/applications

在本地开发时应该放什么?我的IP?

What should I put there when I am developing locally? My IP?

推荐答案

如果你是在本地开发,你可以输入你要重定向到的 URL.例如,如果您在 localhost 的 4000 端口上运行,并且想要重定向到名为 /callback 的路由,则可以输入:

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

在那个领域.

这篇关于Auth0 和 React 的 CORS 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆