How to determine if the user signed in to Firebase with email and password or with google sign in?

前端 未结 4 2494
遥遥无期
遥遥无期 2021-02-10 04:30

I am working on a log in for a web application, and I have made it so the user can sign in manually with their email and password or by using a google sign in. Is there a way to

4条回答
  •  梦如初夏
    2021-02-10 05:19

    Currently @mjdnk asnwer depracated, because it will gives always first provider not the last logged in.

    So most recent solution is:

    As noted here

    var uiConfig = {
            callbacks: {
              signInSuccessWithAuthResult: function(authResult, redirectUrl) {
                var providerId = authResult.additionalUserInfo.providerId;
                localStorage.setItem("firebaseProviderId", providerId)
                //...
              },
              //..
           }
    

    and for display in page

    firebase.auth().onAuthStateChanged(function (user) {
          if (user) {
            user.getIdToken().then(function (idToken) {
    
              $('#user').text(welcomeName + "(" + localStorage.getItem("firebaseProviderId")+ ")");
              $('#logged-in').show();
            }
        }
    });
    

提交回复
热议问题