ngxs-labs / firestore-plugin

Firestore plugin for NGXS
https://ngxs-firebase-plugin.netlify.com/
MIT License
20 stars 14 forks source link

How to re-connect after stream errored due to 'Missing or insufficient permissions'? #49

Closed muellerdberlin closed 2 years ago

muellerdberlin commented 2 years ago

I have the problem, after stream connection errored because of "missing or insufficient permissions" of firestore, I cannot connect to the stream again. It just throws another error of firebase sdk at second try.

First I connect with "cancelprevious: true" attribute in ngxsOnInit:

ngxsOnInit(ctx?: StateContext<MyModel>): void {
    this.ngxsFirestoreConnect.connect(ListenToSomeThing, {
      to: (action) => this.db.collection$(),
      cancelPrevious: true,
    });
}

Then I dispatch the action and want to start the stream somewhere in my code: store.dispatch(new ListenToSomeThing());

Result in console. I'm using StreamErrored and StreamDisconnected to catch the next two logs. image

I try it again (does'nt matter if the second call would have been accepted by firestore or not, it is not started at all, this is the only log): image

My question: How can I catch the firestore problem or reconnect an errored stream by using the firestore plugin? I didn't find something in the documentation yet.

Thank you very much!

joaqcid commented 2 years ago

hi @muellerdberlin

did you try explicitely Disconnect the action that failed before retrying? also, are you sure you are logged in before retrying?

muellerdberlin commented 2 years ago

Thank you @joaqcid I solved it by adding a catchError into the pipe after collection$ call to handle a permission error.

It would be great to have a default way to handle thrown (permission) errors by firebase without showing it in the console (eg. for production purpose), but rather to handle the error (in development or monitoring tools) including the failed path and data.