erizoy
erizoy

Reputation: 129

Missing or insufficient permissions with AngularFirestore

I'm getting following error when I try to get doc form Firestore ([email protected] and angular/[email protected]):

ERROR FirebaseError: Missing or insufficient permissions.

According to firebase's manual, I wrote rules for firestore:

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

Here is the code from my service:

constructor(
    private store: AngularFirestore,
    private db: AngularFireDatabase,
    private auth: AuthService
  ) {
    // this.auth.user$ = this.angularFireAuth.user
    this.auth.user$.subscribe(user => {
      if (user && user.email) {
        this.store.doc('/collection/document').valueChanges().subscribe(_ => {
          console.log(_); // throws ERROR FirebaseError: Missing or insufficient permissions.
        });

        this.db.list<List>(`lists`, ref => ref.orderByChild('owner').equalTo(user.email))
          .valueChanges([], {idField: 'uuid'})
          .subscribe(_ => {
            console.log(_); // works fine
          })
      }
    });
}

I'm a bit familiar with firebase rules, so subscription on rtdb works fine (with production-ready rules). And I can receive data from firestore collection if I change read rules with allow read: if true;, but of course I want rules to be more strict. So the problem looks like request.auth in rules seems to equal null without adequate reason.

Thanks everyone who can help!

Upvotes: 0

Views: 625

Answers (2)

Michel
Michel

Reputation: 36

The problem is in the firebase package : https://github.com/angular/angularfire/issues/2838

I did have the same problems after updating all my packages (angular 12, angular/fire, firebase) It was resolved when i downgraded the fireabase package:

npm i [email protected]

Upvotes: 2

N.F.
N.F.

Reputation: 4182

Try modifying match /collection/document to match /collection/{document} in your rule.

Upvotes: 0

Related Questions