Firestore规则似乎无法正常工作ERROR错误:权限丢失或不足

时间:2018-02-19 15:03:19

标签: javascript google-cloud-firestore angularfire2 firebase-security-rules

我在这里有一个非常简单的查询(使用AngularFire与firestore交互):

initializeEventFeed(): void {
    this.eventCollection = this.db.collection('Events', ref => ref.orderBy('date'));
    this.eventCollection$ = this.eventCollection.valueChanges();
  }

当我的规则设置为:

时,它可以正常工作
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write;
    }
  }
}

但如果我使规则变得更复杂,那么我将获得不足的权限错误:

service cloud.firestore {
  match /databases/{database}/documents {
    match /Events/{event} {
      allow read, write;
    }
  }
}

或更实际的东西(我想要的):

service cloud.firestore {
  match /databases/{database}/documents {
    match /Events/{event} {
      allow read: if request.auth.uid != null;
      allow write: if request.auth.token.email == "authedWriteUser@gmail.com";
    }
  }
}

真正奇怪的是,即使只是flatout将它们设置为true也会给出权限错误:

service cloud.firestore {
  match /databases/{database}/documents {
    match /Events/{event} {
      allow read: if true;
      allow write: if true;
    }
  }
}

1 个答案:

答案 0 :(得分:0)

我只是想重现你的问题,但它对我来说很好。

我的数据:

Data structure in Firestore console

我的规则:

match /48868872/{event} {
  allow read
}

我的代码:

var query = firebase.firestore().collection("/48868872").orderBy('date');

query.get().then((snapshot) => {
  snapshot.forEach((document) => { console.log(document.id); })
}).catch(console.error);

直播链接:https://jsbin.com/kataduw/edit?html,js,console

相关问题