BOOnZ
BOOnZ

Reputation: 848

angular2 firestore detect document no permissions after subscribing

So I have the following piece of code:

this.observable = this.angularFirestore.collection('users').doc<User>(userID).valueChanges();
this.subscription = this.eventObjectObservable.subscribe((user: User) =>
{
    //do something here
});

My question is whether it is possible to detect a loss of permissions after subscribing to the document.

For example, after someone visits a page and successfully loads this document and is subscribing to changes, an administrator may remove permissions from this person to access the said document. How can I detect this (shown in console)

"ERROR Error: Missing or insufficient permissions."

and handle it accordingly? I am thinking of handle it such that when this event is detected, the said user would get redirected to another page.

Upvotes: 0

Views: 24

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317692

I don't know about the API provided by Angular, but the core Firestore API for DocumentReference.onSnapshot() that you'd use to listen to document changes accepts an onError function argument. onError is optional, but it should be invoked if the server decides that the listener should loses access to the target document for whatever reason.

If Angular has no such equivalent, that sounds like a feature request.

Upvotes: 1

Related Questions