0

I am using angularfire2 wth my ionic app and have sign in with facebook enabled.

When first time a user logs in using the fb then i naturally dnt have any record of it in my firebase DB. I want to create a user node using the facebook returned uid as the node.

The way i can retrieve it is like below. I can check by seeing if it has child objects etc. But is that the way recommended to do this kind of checks? I also don't see how to add subscribe or then to it as i would assume this should be async operation for me to wait until it confims me that user does not exist yet. Please advise

const userRef = this.db.object("/users/" + uid)
Vik
  • 8,721
  • 27
  • 83
  • 168
  • check this ionic starter repo with firebase, it has fb sign in and profile customization https://github.com/codediodeio/ionic-firestarter – omurbek Aug 03 '18 at 03:33
  • the above uses angular firestore but i am using firebase realtime DB – Vik Aug 03 '18 at 03:38
  • @Frank you blindly marked it as duplicate. this question is related to angularfire2 which does not have once method. – Vik Aug 03 '18 at 04:12
  • AngularFire is built on top of the Firebase JavaScript SDK. So the method in the linked answer, can be used in our AngularFire code too. If you think you need a different method because you're using AngularFire, show in your question how you're trying to use the check. – Frank van Puffelen Aug 03 '18 at 13:14

2 Answers2

0

Simply building a reference to some location in the database (as shown in the code above) says nothing about whether or not data exists at that location. The location needs to be queried in order to figure out of data exists there.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
0

The sample code get from firebase web API document.

var starCountRef = firebase.database().ref('posts/' + postId + '/starCount'); starCountRef.on('value', function(snapshot) { updateStarCount(postElement, snapshot.val()); });

youDaily
  • 1,372
  • 13
  • 21