Skip to content Skip to sidebar Skip to footer

How To Retrieve And Handle Redirect Errors Using Firebase Auth?

I'm developing mobile first app, using Firebase Auth. Firebase recommends redirect instead of popup. However, I can't seem to find any example of retrieving errors on using Oauth p

Solution 1:

We show where to do error handling for redirect operation in the previous section of the same doc: Just search for "firebase.auth().getRedirectResult()" in this page specifically in the catch here:

firebase.auth().getRedirectResult().then(function(result) {
  if (result.credential) {
    // This gives you a Google Access Token. You can use it to access the Google API.var token = result.credential.accessToken;
    // ...
  }
  // The signed-in user info.var user = result.user;
}).catch(function(error) {
  // Handle Errors here.var errorCode = error.code;
  var errorMessage = error.message;
  // The email of the user's account used.var email = error.email;
  // The firebase.auth.AuthCredential type that was used.var credential = error.credential;
  // ...
});

By the way, adding multiple auth providers and handling linking accounts perfectly is actually quite tricky because there are many sub-flows to take into account (e.g. what if the user wants to link but then signs-in an account where the emails do not match...). I recommend you use Firebase UI which provides a configurable UI component that will handle all these tricky flows for you.

Post a Comment for "How To Retrieve And Handle Redirect Errors Using Firebase Auth?"