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

问题描述 投票:0回答:2

我正在开发一个 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 运行?

firebase cors firebase-authentication cross-domain
2个回答
2
投票

您想在项目的根目录中创建一个 .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)


0
投票

错误:- 控制台中没有显示任何内容并显示 localhost:3000/? 答案:- 将 Firebase 版本从 10 更改为 9。

© www.soinside.com 2019 - 2024. All rights reserved.