GVKun编程网logo

Firestore 安全规则和 Swift(line of fire 安全)

4

对于Firestore安全规则和Swift感兴趣的读者,本文将提供您所需要的所有信息,我们将详细讲解lineoffire安全,并且为您提供关于@firebase/firestore:Firestore

对于Firestore 安全规则和 Swift感兴趣的读者,本文将提供您所需要的所有信息,我们将详细讲解line of fire 安全,并且为您提供关于@firebase/firestore: Firestore (8.6.2): 无法访问 Cloud Firestore 后端 (React Js)、@firebase/firestore:Firestore (8.3.3):无法访问 Cloud Firestore 后端、@firebase/firestore:Firestore (8.6.5):无法访问 Cloud Firestore 后端、android stopListening() 上云 Firestore 的 firebase-UI 是否真的停止监听来自 firestore 的数据?的宝贵知识。

本文目录一览:

Firestore 安全规则和 Swift(line of fire 安全)

Firestore 安全规则和 Swift(line of fire 安全)

如何解决Firestore 安全规则和 Swift

我正在为 Firestore 安全规则苦苦挣扎。这是我的用户集合的结构,我还有其他集合的结构:机器、日志和照片。我想设置规则,只有当 request.auth.uid == user.user_UUID

时才能访问数据

我认为我的规则中的语法一定不正确,因为根据我的以下内容,在使用我的应用程序登录后,我无法读取或写入任何数据。认为 user_UUID 周围的括号可能是问题我尝试将“匹配用户/{user_UUID}”更改为“匹配用户/user_UUID”,但这没有用。我也尝试删除 ''match /{document=**} ''

我的每个集合都有一个 user_UUID 字段,我希望保护安全性,以便只有相应的经过身份验证的用户才能访问该数据。

  1. import Foundation
  2. struct User: Codable {
  3. var email: String?
  4. var userUUID: String?
  5. }
  1. service cloud.firestore {
  2. match /databases/{database}/documents {
  3. match /{document=**} {
  4. match /users/{user_UUID} {
  5. allow read,update,delete: if request.auth != null && request.auth.uid == user_UUID;
  6. allow create: if request.auth != null;
  7. }
  8. }
  9. }
  10. }

解决方法

我想我看到了我的问题。当我创建一个新的经过身份验证的用户时,在我的用户集合中,UUID 被捕获为一个字段,而用户本身的 documentID 正在获取它自己的标识符,我在用户中将其作为属性 userDocumentID 单独捕获。

  1. let db = Firestore.firestore()
  2. let usersRef = db.collection("users")
  3. let newUser = usersRef.document()
  4. let docID = newUser.documentID ///*** THIS MUST BE WHERE PROBLEM LIES
  5. let userData = [
  6. //"date": "","user_UUID": result!.user.uid,"userDocumentID": docID,"nameLast": lastName,"nameFirst": firstName,"email": email,"unlimited": false,"password": password] as [String : Any]
  7. newUser.setData(userData)
  8. self.user_UUID = result!.user.uid
  9. }
,

我一直在做更多的阅读,并想知道我的数据库结构是否天生错误。我有 4 个不同的集合,其中没有一个嵌套在另一个集合中。我使用每个键值将它们链接在一起。

所以我有 machine.user_UUID 将文档链接到正确的记录。

但我看到也许我应该有一个路径,例如 user/machines

这可能是我问题的根源吗?

@firebase/firestore: Firestore (8.6.2): 无法访问 Cloud Firestore 后端 (React Js)

@firebase/firestore: Firestore (8.6.2): 无法访问 Cloud Firestore 后端 (React Js)

如何解决@firebase/firestore: Firestore (8.6.2): 无法访问 Cloud Firestore 后端 (React Js)

我正在尝试将我的 react js 应用程序与 Firebase Firestore 连接,但出现以下错误,如图 error image 我在集合中有 2 个文档,但我得到一个空的您可以在控制台中看到的数组。这是我用来获取 firestore 数据的代码

const snapshot = await firebase.firestore().collection(''users'').get();
const data = snapshot.docs.map((doc) => doc.data());
console.log(data);

PS:我可以正确使用来自 firebase 的 auth 功能,但在使用 firestore 时出现错误。

到目前为止我尝试过的解决方案:

  1. 同步时钟
  2. 验证了 firebase 规则并确保允许读写(附上我在 firestore 规则部分找到的规则)
rules_version = ''2'';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read,write: if 
          request.time < timestamp.date(2021,6,23);     
    }
  }
}

自从昨晚以来我一直在努力寻找一些快速的解决方案。提前致谢。

解决方法

我尝试了以下步骤来确认 React 应用程序或浏览器存在问题并修复了问题。

  • 尝试使用 node 和 express 获取数据并将数据发布到 Firestore 脚本(这有助于发现问题不在于 firebase 配置)

  • 经过一些在线研究后,我尝试将浏览器从 Brave 更改为 真正有效的 Chrome。

,

屏幕截图中的第一个错误暗示这实际上是一个 Access-Control-Allow-Origin CORS 问题。因此,为了像您在 this article 中看到的那样修复它,您可以:

  • "proxy": "http://localhost:PORT_YOU_ARE_USING" 选项添加到您的 package.json 文件中;

  • 使用像 http-proxy-middleware 这样的中间件来代理请求,您可以按照文章中的示例进行操作。

您还可以查看此 community question,它与您的问题类似,并提供了一些其他解决方案。通过查看,您可能会更好地了解 React 中的 cors 问题。

@firebase/firestore:Firestore (8.3.3):无法访问 Cloud Firestore 后端

@firebase/firestore:Firestore (8.3.3):无法访问 Cloud Firestore 后端

如何解决@firebase/firestore:Firestore (8.3.3):无法访问 Cloud Firestore 后端

在添加了 eslint 并且没有更改代码之后,我运行了我昨天运行良好的应用程序。我最终收到以下错误:

[2021-04-09T04:47:33.960Z]  @firebase/firestore: Firestore (8.3.3): Could not reach Cloud Firestore backend. Connection Failed 1 times. Most recent error: FirebaseError: [code=invalid-argument]: 3 INVALID_ARGUMENT: Invalid resource field value in the request.
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.

我也看到了一些其他的 stackoverflow 帖子和 github 问题,而且大多数人以前似乎也遇到过同样的问题。我尝试了一些建议的解决方案 - 降级 Firebase、检查我的互联网等 - 似乎没有任何效果。

@firebase/firestore:Firestore (8.6.5):无法访问 Cloud Firestore 后端

@firebase/firestore:Firestore (8.6.5):无法访问 Cloud Firestore 后端

如何解决@firebase/firestore:Firestore (8.6.5):无法访问 Cloud Firestore 后端

我之前使用过 expo,但我退出了我的项目,一切正常,除了我的 firebase 连接。它说:@firebase/firestore: Firestore (8.6.5): 无法访问 Cloud Firestore 后端。后端没有在 10 秒内响应。

  1. import firebase from ''firebase'';
  2. import ''@firebase/firestore'';
  3. const firebaseApp = firebase.initializeApp({
  4. apiKey: ''AIzaSyALTdavPNQReVJNWyc2aF8DfexzxzDoXB0'',authDomain: ''projetofinal-e1147.firebaseapp.com'',projectId: ''projetofinal-e1147'',storageBucket: ''projetofinal-e1147.appspot.com'',messagingSenderId: ''546669005614'',appId: ''1:546669005614:web:1b06c375565e04b4c888bf'',measurementId: ''G-KLJBEWBR3S'',});
  5. class Fire {
  6. constructor(callback) {
  7. this.init(callback);
  8. }
  9. init(callback) {
  10. if (!firebase.apps.length) {
  11. firebase.initializeApp(firebaseConfig);
  12. }
  13. firebase.auth().onAuthStateChanged(user => {
  14. if (user) {
  15. callback(null,user);
  16. } else {
  17. firebase
  18. .auth()
  19. .signInAnonymously()
  20. .catch(error => {
  21. callback(error);
  22. });
  23. }
  24. });
  25. }
  26. getLists(callback) {
  27. let ref = this.ref.orderBy(''color'');
  28. this.unsubscribe = ref.onSnapshot(snapshot => {
  29. lists = [];
  30. snapshot.forEach(doc => {
  31. lists.push({id: doc.id,...doc.data()});
  32. });
  33. callback(lists);
  34. });
  35. }
  36. addList(list) {
  37. let ref = this.ref;
  38. ref.add(list);
  39. }
  40. deleteList(list) {
  41. let ref = this.ref;
  42. ref.doc(list.id).delete();
  43. }
  44. updateList(list) {
  45. let ref = this.ref;
  46. ref.doc(list.id).update(list);
  47. }
  48. get userId() {
  49. return firebase.auth().currentUser.uid;
  50. }
  51. get ref() {
  52. return firebase
  53. .firestore()
  54. .collection(''users'')
  55. .doc(this.userId)
  56. .collection(''lists'');
  57. }
  58. detach() {
  59. this.unsubscribe();
  60. }
  61. }
  62. export default Fire;

这是我的 Firebase 文件,它在我的 expo 应用程序中工作,但不再是了。

解决方法

添加:

  1. if (!firebase.apps.length) {
  2. firebase.initializeApp(firebaseConfig);
  3. + firebase.firestore().settings({ experimentalForceLongPolling: true,merge: true });
  4. }

android stopListening() 上云 Firestore 的 firebase-UI 是否真的停止监听来自 firestore 的数据?

android stopListening() 上云 Firestore 的 firebase-UI 是否真的停止监听来自 firestore 的数据?

如何解决android stopListening() 上云 Firestore 的 firebase-UI 是否真的停止监听来自 firestore 的数据?

我想在数据达到一定值时实现stopListening(),Documentation明确指出

stopListening() 调用会冻结 RecyclerView 中的数据并阻止以后加载数据页面

我在我的 recyclerview 上实现它到 RecyclerViewAddOnScrollListener 上的 stopListening(),

       override fun onScrolled(recyclerView: RecyclerView,dx: Int,dy: Int) {
            super.onScrolled(recyclerView,dx,dy)
            val totalItem = adapter?.itemCount ?: 0

            if (totalItem > itemmax && dy > 0){
                adapter?.stopListening()
                Log.d(MusimArsipFragment::class.java.name,"item didapat = " + adapter?.itemCount)}

        }

我还尝试通过实现一个按钮来实现 stopListening() 数据来手动停止它,但由于某种原因,两者都不起作用!当我在页面底部时,数据继续加载,我试图删除缓存,以防它从缓存中加载数据并进行大量试验和错误,因此我几乎可以肯定它总是从消防站。我是不是脑子都被冻住了,解决办法其实很简单?提前致谢。

关于Firestore 安全规则和 Swiftline of fire 安全的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于@firebase/firestore: Firestore (8.6.2): 无法访问 Cloud Firestore 后端 (React Js)、@firebase/firestore:Firestore (8.3.3):无法访问 Cloud Firestore 后端、@firebase/firestore:Firestore (8.6.5):无法访问 Cloud Firestore 后端、android stopListening() 上云 Firestore 的 firebase-UI 是否真的停止监听来自 firestore 的数据?的相关知识,请在本站寻找。

本文标签: