Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's not clear to me from your code that you are returning the reference after auth has completed. Specifically:</p> <pre class="lang-js prettyprint-override"><code>ref: function(path) { var self = this; var ref = new Firebase(self.url + path); ref.auth(self.auth_token, function(err) { if (err &amp;&amp; console) console.log("Firebase "+path+" login failed!"); else if (console) console.log("Firebase "+path+" login succeeded."); }); return ref; } </code></pre> <p>is returning the reference immediately. The callback to auth is asynchronous, so if you're using your ref before the callback is called your session will be unauthenticated.</p> <p>It looks like you are using Angular, so I whipped a small example, which worked correctly with the same security rules as you: <a href="https://gist.github.com/anantn/5304404" rel="nofollow">https://gist.github.com/anantn/5304404</a></p> <p>If I were to rewrite your code, I would do it as follows:</p> <pre class="lang-js prettyprint-override"><code>bind: function(path) { var ref = new Firebase(self.url + path); var d = self._q.defer(); // Assign $q to this._q in constructor. ref.auth(self.auth_token, function(err) { if (!err) { ref.once("value", function(snap) { d.resolve(snap.val()); }); } }); return d.promise; } ... // In the controller: $scope.list = $$firebase.bind("/data"); </code></pre> <p>I highly recommend using promises via the $q module to ensure you don't use the Firebase reference before the auth has completed. An even better solution would be to use the official Firebase bindings for Angular that already takes care of all this for you: <a href="https://github.com/firebase/angularFire" rel="nofollow">https://github.com/firebase/angularFire</a> </p> <p>Hope this helps!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload