【问题标题】:How to use firebase project's auth for other project's firestore?如何将firebase项目的身份验证用于其他项目的firestore?
【发布时间】:2021-02-08 04:57:56
【问题描述】:

我有一些 Firebase 项目。
用于签名的认证项目。以及用于存储的 firestore 项目。

firestore 项目的规则是

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if false;
    }
  }
}

以前,我通过 firebase 函数使用 firebase admin sdk 来获得对 firestore 项目的全部控制。

当规则如下时,是否可以在客户端上使用 auth for firestore

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth != null;;
    }
  }
}

简单来说,我已经实现了...

if (!this.auth && !_auth) {
      this.authApp = firebase.initializeApp(Env.FirebaseAuthConfig, 'auth')
      this.auth = this.authApp.auth()
    }

    if (!this.firestore && !_firestore) {
      this.firestoreApp = firebase.initializeApp(Env.FirebaseFirestoreConfig, 'firestore')
      this.firestoreApp.auth(this.authApp)
      this.firestore = this.firestoreApp.firestore()
    }

但 FirebaseError: 请求时发生权限缺失或不足

请给我一些建议

【问题讨论】:

    标签: firebase google-cloud-firestore firebase-authentication firebase-security


    【解决方案1】:

    为什么不在同一个项目中使用 Auth 和 Firestore?如果您在与 Firestore 相同的项目中设置 Auth,那么可以,您可以使用 if request.auth != null; 安全规则。

    此外,this video 的开头解释了身份验证的工作原理,以便客户端可以使用它。

    【讨论】:

      猜你喜欢
      • 2017-05-24
      • 2019-12-12
      • 1970-01-01
      • 1970-01-01
      • 2018-04-05
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多