I'm using firebase auth with Firestore (https://github.com/angular/angularfire2) in my app. With my current Firestore rules, I make sure to unsubscribe from every observable retrieved from Firestore before I signout. However, I get a "FirebaseError: Missing or insufficient permissions." error, which I traced down to a nested subscription I subscribe to within a subscription as in the below code.
Inside ngOnDestory I unsubscribe from both subscriptions, but I still get the previous error.
this.proposalSubscription = this._posts.retrieveProposals(user.uid)
.subscribe(proposals => {
this.proposals = proposals;
this.proposals.forEach(proposal => {
this.chatSubscription = this._chat.retrieveChat(proposal.id).subscribe(chat => {
if (chat) {
this.chats.set(proposal.id, chat)
}
});
})
});
I am almost sure now the issue is in this line: this.chatSubscription = this._chat.retrieveChat(proposal.id).subscribe(chat => ...
Even though I unsubscribe from both proposalSubscription and chatSubscription before signing out, I still get the error. Any idea on how can I fix this? Also, I don't have much experience with rxjs and the operators. Is there an operator I could use to avoid this nested subscription?
Thanks in advance.