I am using Ionic2
with Angularfire2
to access Firebase Authentication
.
I access the following rxjs/Observable
:
chats.ts
this.firelist = this.dataService.findChats();
this.subscription = this.firelist.subscribe(chatItems => {
...
});
ngDestroy() {
this.subscription.unsubscribe();
}
dataService.ts
findChats(): Observable<any[]> {
this.firebaseDataService.findChats().forEach(firebaseItems => {
...
observer.next(mergedItems);
});
}
firebaseDataService.ts
findChats(): Observable<any[]> { // populates the firelist
return this.af.database.list('/chat/', {
query: {
orderByChild: 'negativtimestamp'
}
}).map(items => {
const filtered = items.filter(
item => (item.memberId1 === this.me.uid || item.memberId2 === this.me.uid)
);
return filtered;
});
}
Also, in Firebase Authentication, I have the following Realtime Database Rules:
"rules": {
".read": "auth != null",
".write": "auth != null",
}
Problem
This works perfectly while a user is logged in (i.e. auth != null
), but a soon as a user logs out, and auth == null
, I get the following error:
ERROR Error: Uncaught (in promise): Error: permission_denied at /chat: Client doesn't have permission to access the desired data. Error: permission_denied at /chat: Client doesn't have permission to access the desired data.
Question
As you can see in the above code, I try to unsubscribe
from the Firebase Authentication Service, but must be doing it incorrectly. If anyone can advise how I should unsubscribe
in order to stop my app querying the Firebase database, I would appreciate the help.
this.firelist.unsubscribe()
– Vamshithis.firelist
is arxjs/Observable<any>
, and the api does not have anunsubscribe
function. It does however, return aSubscription
that does have one, so that's what I unsuccessfully try as shown above. reactivex.io/rxjs/class/es6/Observable.js~Observable.html – Richarduid
. You can do something like: ` "chat": { "$key": { ".read": "data.child('memberId1').val() === auth.uid || data.child('memberId2').val() === auth.uid || true", ".write": "data.child('memberId1').val() === auth.uid || data.child('memberId2').val() === auth.uid || true" } },` – Richard