My users can like a list of heroes, so I have this structure in my firebase rules/datas:
"user_flags": {
  "$uid": {
    ".write": "auth.uid == $uid",
    ".read": "auth.uid == $uid",
    "liked": {
      "$heroIdx": {
        ".validate": "newData.isString()" 
      }
    }
  }
}
In my code I want to subscribe to the "liked heroes" ref, so that's what I do:
import { Injectable } from '@angular/core';
import { AngularFireDatabase } from 'angularfire2/database';
import { Observable } from 'rxjs/Observable';
import { AngularFireAuth } from 'angularfire2/auth';
@Injectable()
export class UserFlagsService {
  likedHeroes$: Observable<string[]>;
  constructor(
    private afAuth: AngularFireAuth,
    private db: AngularFireDatabase
  ) {
    this.likedHeroes$ = afAuth.authState.flatMap(user => {
      return user && user.uid
        ? this.db.list(`user_flags/${user.uid}/liked`)
                 .map(heroes => heroes.map(hero => <string>hero.$value))
        : Observable.of([])
    });
  }
}
Everything works fine until the user signs out... Even with the check on user and user.uid the query user_flags/MY_ID_HERE/liked seems to be triggered and I get a "permission denied".
I tried to use subscribe and watch for signout to unsubscribe but it didn't work either... The query was still triggered and failed with "permission denied"
How should I handle this ? I want my service to return a reliable observable so I can subscribe to it in my components.
Thanks a lot for your help
 
     
    