title: Angularfire2 read data once
body: <p>Whenever the user is logging in, I run this to save his data in my <code>users</code> node. Unlucky, whenever the user logs out I get this error:</p>
  
  <pre><code>FIREBASE WARNING: Exception was thrown by user callback. Error: permission_denied at /users/userID: Client doesn't have permission to access the desired data.
      at Error (native)
      at G (http://localhost:4200/main.bundle.js:75367:36)
      at Object.G (http://localhost:4200/main.bundle.js:75371:86)
      at yh (http://localhost:4200/main.bundle.js:75356:98)
      at nh.h.wd (http://localhost:4200/main.bundle.js:75349:310)
      at af.wd (http://localhost:4200/main.bundle.js:75252:364)
      at vd.hg (http://localhost:4200/main.bundle.js:75250:280)
      at yd (http://localhost:4200/main.bundle.js:75203:464)
      at WebSocket.La.onmessage (http://localhost:4200/main.bundle.js:75202:245)
      at WebSocket.wrapFn [as _onmessage] (http://localhost:4200/main.bundle.js:94097:29) 
  </code></pre>
  
  <p>which means Firebase keep listening to my user until the page is redirected. so I need try run it only once. any ideas?</p>
  
  <p>In the user panel, I have this code: </p>
  
  <pre><code>ngOnInit() {
          this.authService.loadUser().subscribe(() =&gt; {
              this.user = this.authService.userData;
          });
    }
  </code></pre>
  
  <p>Which refers to my <code>loadUser()</code> method to get the data from firebase (I just tried to place take(1) but I still get this permission error):</p>
  
  <pre><code>loadUser() {
        return this.af.database.object('/users/'+this.uid).take(1).map(user =&gt; {
              this.userData = user;
          });
    }
  </code></pre>
  
  <p>In my logout I simply do this:</p>
  
  <pre><code>logout() {
        this.auth.logout();
        this.userData = null;
      this.isLoggedIn = false;
      this.router.navigate(['']);
    }
  </code></pre>
  
  <p>I think the error occurs because firebase is keeping the connection to my user even after <code>this.auth.logout();</code> and until the router is navigating, he keeps trying to refresh the data. That's why I need to perform this action only once.</p>