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

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

问题描述

我目前正在尝试在我的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头。原因 http:// localhost:3000 因此不允许
访问。对预检请求的响应不通过访问控制
检查:
请求的资源上没有Access-Control-Allow-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?

最好的问候


as RodrigoLópezDato指出,我可以在我的应用程序中写下Origins: https://manage.auth0.com/ #/ applications

当我在本地开发时,我应该在那里放什么?我的IP?

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

推荐答案

如果您在本地开发,可以将要重定向到的URL。例如,如果您在本地端口400上运行,并且您想重定向到您的路由 / 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 400, and you want to redirect to your route called /callback, you can put:

http://localhost:4000/callback

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

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