I have an ionic3 application using angularfire2 and firebase. I use firbase auth to login to my application, and for retrieving an object from firebase about "currentChallenges". When I use the logout function an error is thrown from Firebase.
Error message:
permission_denied at /currentChallenge: Client doesn't have permission to access the desired data.
I use the following function for my logout, in my auth.service.ts:
logout() {
this.isLoggedIn = false;
this.firebaseAuth
.auth
.signOut().then(() => {
this.appCtrl.getRootNav().popToRoot(); //root is login page
});
}
I am not sure where/what exactly is causing the error. In my challenges.service.ts is where I make the initial observable object:
private dbCurrentChallengesObservable: FirebaseObjectObservable <any>;
constructor(db: AngularFireDatabase) {
this.dbCurrentChallengesObservable = db.object('/currentChallenge');
}
public getCurrentChallenges(){
return this.dbCurrentChallengesObservable;
}
And then, I use this object in my model (challenges.ts) like this:
ionViewCanEnter(): boolean{
return this.authService.isAuthenticated();
}
ionViewDidLoad() {
this.currentChallenge = this.challengesService.getCurrentChallenges();
this.currentChallenge.subscribe(data => {
if(data.challenge1completed > 0) this.challenge1Completed = true;
if(data.challenge2completed > 0) this.challenge2Completed = true;
});
}
At first I thought it was related to the subscribe and I added an subscribe().unsubscribe() in an on-ion-leave function in the challenges.ts, but that did not stop the error. But something must still be listening to firebase, which must be stopped upon or even before logout. I just don't know what/where/how.
Any help would be appreciated.