即使规则设置为true,也可以用Firebase响应CORS问题 [英] React CORS issue with firebase even though rule is set to true

查看:89
本文介绍了即使规则设置为true,也可以用Firebase响应CORS问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有99%的把握可以为自己的Firebase实时数据库正确设置规则。
React-Redux用于两个调用firebase
的react应用程序,但是问题很令人费解,
1)我创建了一个新的react应用程序并尝试执行axios POST / GET到firebase,但CORS错误不断发生

I am 99% sure that i set the rules correctly for my firebase realtime database. React-Redux is used for by both react app that call the firebase However the problem is quite puzzling, 1) I created a new react app and try to do an axios POST/GET to the firebase but CORS error keep happening

2)我使用了旧的react应用并调用了与(1)没有CORS错误相同的API,并且POST请求通过了。

2) I used my old react app and call the same API as (1) no CORS error and the POST request went through.

3)我测试了API是否使用邮递员,POST和GET请求都通过了

3) I test that the API works using postman, both POST and GET request went through

4)我还验证了Firebase在域下的权限设置中是否允许localhost

4) I also verified that localhost was allowed in the permission setting under domain for firebase

任何人都知道哪里出了问题吗?

Anyone got any idea what is wrong?

错误:


在' https://...firebaseio./Employee.json '
来自来源' http:// localhost:3000 '已被CORS策略阻止:
对预检请求的响应未通过访问控制检查:响应
中 Access-Control-Allow-Credentials标头的
值为,当请求的凭据模式为$ b时必须为 true $ b包括。由
XMLHttpRequest发起的请求的凭据模式由withCredentials属性控制。

Access to XMLHttpRequest at 'https://...firebaseio./Employee.json' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.



employee.js:42 Error: Network Error
    at createError (createError.js:17)
    at XMLHttpRequest.handleError (xhr.js:80)


推荐答案

@Jered解决方案,通过添加WithCredential解决了该问题

@Jered solution by adding WithCredential solved the issue

这篇关于即使规则设置为true,也可以用Firebase响应CORS问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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