Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularFirestore缺少或权限不足(Firebase自定义令牌身份验证)_Javascript_Angular_Google Cloud Firestore_Firebase Security_Angularfire - Fatal编程技术网

Javascript AngularFirestore缺少或权限不足(Firebase自定义令牌身份验证)

Javascript AngularFirestore缺少或权限不足(Firebase自定义令牌身份验证),javascript,angular,google-cloud-firestore,firebase-security,angularfire,Javascript,Angular,Google Cloud Firestore,Firebase Security,Angularfire,我一直在尝试从firestore读取数据,但无法执行此操作 async authUser() { let token = this._tokman.getUserToken(); await this._afa.signInWithCustomToken(token); } 从服务器获取令牌并将其传递给firebase以对用户进行身份验证。 然后调用firestore获取数据 async data() { await this._afa.onAuthStateCha

我一直在尝试从firestore读取数据,但无法执行此操作

async authUser() {
    let token = this._tokman.getUserToken();
    await this._afa.signInWithCustomToken(token);
  }
从服务器获取令牌并将其传递给firebase以对用户进行身份验证。 然后调用firestore获取数据

async data() {
    await this._afa.onAuthStateChanged(user => {
      if (user) {
        this._afs.collection('gps-data').doc(user.uid)
          .valueChanges()
          .subscribe(res => {
            console.log(res);
          }, err => {
            console.log(err);
          })
      }
    })
  }
但是从firestore获取此错误

FirebaseError: Missing or insufficient permissions.
at new e (http://localhost:4200/vendor.js:51950:23)
at http://localhost:4200/vendor.js:62177:28
at http://localhost:4200/vendor.js:62178:18
at e.onMessage (http://localhost:4200/vendor.js:62200:10)
at http://localhost:4200/vendor.js:62117:26
at http://localhost:4200/vendor.js:62148:37
at http://localhost:4200/vendor.js:66953:31
at ZoneDelegate.invoke (http://localhost:4200/polyfills.js:460:30)
at Zone.run (http://localhost:4200/polyfills.js:219:47)
at http://localhost:4200/polyfills.js:953:40
firestore的安全规则是

 service cloud.firestore {
  match /databases/{database}/documents {
    match /gps-data/{userid} {
        allow read: if request.auth.token.sub == userid;
    }
   
  }
}
还将jwt令牌添加到http头中。 请告诉我哪里做错了

更新 解决方法:更改firebase版本 从


在不更改安全规则的情况下

问题在于此行中的
令牌.sub

request.auth.token.sub == userid;
令牌的
sub
是为其生成该令牌的项目ID。所以你要比较一个项目ID和一个用户ID,这两个ID中的任何一个都不一样

您希望在此处比较两个用户ID,即:

request.auth.uid == userid;

我强烈建议您花些时间阅读有关安全规则的文档,特别是中的部分。

如果您使用的是自定义令牌,您可以从两个位置获取uid,一个来自auth,另一个来自idToken。uid:。无论如何,谢谢你的帮助。
request.auth.token.sub == userid;
request.auth.uid == userid;