firebase - 如何从http ://localhost:3000访问Firebase

标签 firebase cors firebase-authentication cross-domain

我正在开发一个 React 应用,在尝试使用其电子邮件身份验证提供商登录 Firebase 时收到此错误。

Failed to load https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key=.....: 
Response to preflight request doesn't pass access control check: The
'Access-Control-Allow-Origin' header has a value 'https://localhost:3000' 
that is not equal to the supplied origin. Origin 'http://localhost:3000'
is therefore not allowed access.

(请注意第 3 行的 https 与第 4 行的 http)

看起来他们将 Access-Control-Allow-Origin* 更改为您所调用的任何域的 https 版本来自?

这是否意味着我现在需要配置我的 React 应用程序以 https://localhost:3000 运行?

最佳答案

您想要在项目的根目录中创建一个 .env 文件并设置 HTTPS=true。这将使用自签名证书启动您的应用程序。

在这里查看create-react-app的高级配置选项

https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#advanced-configuration

如果您需要对证书进行更多控制并且不想弹出。看看react-app-rewired (https://github.com/timarney/react-app-rewired)。您可以使用此处的扩展配置选项将 devServer 配置为使用自定义证书 ( https://github.com/timarney/react-app-rewired#extended-configuration-options )

关于firebase - 如何从http ://localhost:3000访问Firebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52580920/

相关文章:

android - firebase (fcm) 说 401 未经授权

node.js - Node js 计数器值不会增加

Swift 3 从 Firebase 获取用户数据

CORS请求到IP而不是域名

ruby-on-rails - 为什么我的 HTTP Origin header 与 request.base_url 不匹配以及如何修复?

javascript - Firebase 网络电话号码身份验证不起作用

swift - 如何将 Firebase Auth 添加到已添加 Firebase 的 .xcworkspace

android - Firebase 实时数据库根据查询的值返回 ArrayList 或 HashMap

javascript - 如何修复 IE11 中请求 header 内容类型缺失的问题 | Angular 8 应用程序

firebase - 如何向 firebase.auth() 添加附加信息