I'm using Firebase + Ionic in a project. my problem comes when loging out. I am subscribed to several onSnapshot
events in some collections. I expect all subscriptions to be dismissed whenever the a user is logged out, but it is not like that, so whenever I logged out I receive several errors comming from Firebase:
Uncaught Error in onSnapshot: Error: Missing or insufficient permissions.
Here my code:
My controller
/**
* Logout button 'click' event handler
*/
onLogoutPressed(){
this.fbAuthServ.logout().then(() => {
this.navCtrl.setRoot(LoginPage);
});
}
My service provider
// Firebase Modules
import { AngularFireAuth } from 'angularfire2/auth';
constructor(private afAuth: AngularFireAuth, private utils: UtilsProvider){}
...
/**
* Firebase Logout the current user
*/
async logout(){
this.afAuth.auth.signOut();
}
Could you please tell me what should I do to avoid those Missing or insufficient permissions
errors??
Thank you in advance!
EDIT: How I get subscribe to onSnapshot events
Controller
ionViewDidEnter(){
this.fbDataServ.getPlacesByUserAllowed().onSnapshot(placeReceived=> {
this.placesByUserAllowed = placeReceived.docs.map(placeSnapshot => {
return this.utils.mapPlaceSnapshot(placeSnapshot )
});
this._concatPlaces();
//Dismiss loading whenever we have data available
this.utils.dismissLoading();
});
Service Provider
// Firebase
import { AngularFirestore, AngularFirestoreCollection } from 'angularfire2/firestore';
constructor(private afs: AngularFirestore, private fbAuthServ: FirebaseAuthServiceProvider, private utils: UtilsProvider) { }
placesCollection: AngularFirestoreCollection<PlaceModel> = this.afs.collection("places");
/**
* Gets the collection of places where the user is 'allowed'
*/
public getPlacesByUserAllowed(){
return this.placesCollection.ref
.where('users.' + this.fbAuthServ.getCurrentUser().uid + '.allowed', '==', true);
}