如何知道已登录的用户是新创建的用户还是现有用户?

时间:2017-11-10 08:46:29

标签: android firebase firebase-authentication

在firebase中,您实际上不需要使用createUserWithEmailAndPassword()来创建用户(也不可能在不登录其他帐户的情况下) 但你可以使用signInWithCredential()所有情况,即创建和登录。 因此,鉴于我对新用户和现有用户使用signInWithCredential(),我如何区分这两者。

这里他们的sample writeNewUser()正在调用所有onAuthSuccess案例,而不只是新用户。

如何判断签名用户是新用户还是现有用户?

1 个答案:

答案 0 :(得分:2)

您可以告诉 <script> function readURL(input) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function (e) { $(input).next().find('img').attr('src', e.target.result); } reader.readAsDataURL(input.files[0]); } }; </script> 中返回的AuthResult中的现有用户和新用户: here

它提供了一个getter:signInWithCredential,它返回getAdditionalUserInfo(),提供AdditionalUserInfo来判断用户是新用户还是现有用户:https://firebase.google.com/docs/reference/android/com/google/firebase/auth/AuthResult