1

I use a simple AngularJS service to detect if the user is logged in or not using the authenticated key stored in the local storage. If the user is authenticated, then the app reaches firebase to grab the data.

This works fine for logging in users and logging them out. The problem is when the the session expires automatically, the app tries to grab the data without knowing that the session has expired and that returns an error due to the security rules.

$firebase(dataBase.child(permanentStorage['uid']).child('Notes')).$asArray();
// var permanentStorage = window.localStorage;

I couldn't find any ways to add a callback function to the code above.

2
  • Are you looking to get notified when $asArray() loads the data? Commented Aug 19, 2014 at 20:49
  • no when it is unable to load the data. Commented Aug 19, 2014 at 21:26

1 Answer 1

4

Most of the methods return a promise. Promises provide a success and error callback. The $loaded method is triggered after data is received from the server, so it makes a great use case for your request:

var list = $firebase(dataBase.child(permanentStorage['uid']).child('Notes')).$asArray();    
list.$loaded().catch(function(err) {
   console.error(err);
});

However, Firebase will raise a console.warn or console.error on any security error (failure to retrieve data), so this shouldn't be necessary.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.