简体   繁体   中英

Firebase, detect how user connected (Google, Facebook, Email …)

Is there a way to know how a user connected in firebase (facebook, google, email ..). If possible, I would like to get this information with javascript

在此处输入图片说明 Here is a list of most commonly used providers .

                switch (user.providerData[0].providerId) {
                    case "facebook.com":
                        console.log("Used facebook to login");
                        break;
                    case "google.com":
                        console.log("Used facebook to login");
                        break;
                    case "password":
                        console.log("Used email and pass to login");
                        break;
                    case "twitter.com":
                        console.log("Used twitter to login");
                        break;
                    case "github.com":
                        console.log("Used github to login");
                        break;
                    case "apple.com":
                        console.log("Used apple provider to login");
                        break;
                    case "yahoo.com":
                        console.log("Used yahoo provider to login");
                        break;
                    case "hotmail.com":
                        console.log("Used hotmail provider to login");
                        break;
                    default:
                        console.log("user is signed in with unknown provider")
                    }
            });

I assume that you're looking for providerId .

This is taken from Firebase auth's official documentation ( https://firebase.google.com/docs/auth/web/manage-users ):

var user = firebase.auth().currentUser;

if (user != null) {
  user.providerData.forEach(function (profile) {
    console.log("Sign-in provider: " + profile.providerId);
    console.log("  Provider-specific UID: " + profile.uid);
    console.log("  Name: " + profile.displayName);
    console.log("  Email: " + profile.email);
    console.log("  Photo URL: " + profile.photoURL);
  });
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM