allegutta
allegutta

Reputation: 5644

Wait until the user object is received

I am looking for a way to wait until the user object is received, before proceeding with the logic in the app.

saveFacebookCredentialsToFirebase(){

    AccessToken.getCurrentAccessToken().then( (data) => {
      let accessToken = data.accessToken
      let facebookCredential = Firebase.auth.FacebookAuthProvider.credential(accessToken)

      Firebase.auth().signInWithCredential(facebookCredential).catch(function (error) {
          let errorCode = error.code
          let errorMessage = error.message
          let email = error.email
          let credential = error.credential
      })
    })
  }

How can I wait until Firebase.auth().signInWithCredential(facebookCredential) returns a valid user object with user.uid (and not just the promise), before proceeding with the logic in the app?

Upvotes: 2

Views: 1140

Answers (1)

nabn
nabn

Reputation: 2408

I'd do something like:

Firebase.auth()
.signInWithCredential(facebookCredential)
.then(response => {
 /* your logic here */
})
.catch(error => handleError())

Upvotes: 4

Related Questions