![](/img/trans.png)
[英]Firebase Authentication: How to know if account with Google or Facebook provider already exist?
[英]how I can check if the email is already exist in authentication firebase
我有这个 function 在我的 firebase 中创建authentication
,但问题是当用户输入一个已经存在的 email 时,我的应用程序将停止com.google.firebase.auth.FirebaseAuthUserCollisionException: The email address is already in use by another account.
我如何检查身份验证中是否已存在 email
fun createUserWithEmailAndPassword(email: String, password: String) {
viewModelScope.launch(Dispatchers.IO) {
auth
.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener { task ->
if (task.isSuccessful) {
user.userID = auth.uid!!
Log.d("TAG", "${auth.uid}")
addUser(user)
} else {
Log.d("userVM" ,task.result.toString())
}
}
}
}
FirebaseAuth#createUserWithEmailAndPassword(@NonNull email: String, @NonNull password: String)方法:
尝试使用给定的 email 地址和密码创建一个新的用户帐户。 如果成功,它还会将用户登录到应用程序中。
这意味着如果您尝试创建一个已经存在的用户,则会抛出FirebaseAuthUserCollisionException :
由于与另一个现有用户发生冲突而无法完成对 FirebaseUser 实例的操作时抛出。
如果用户已经存在,您应该调用另一个方法,该方法只登录被调用的用户
signInWithEmailAndPassword(@NonNull email:字符串,@NonNull 密码:字符串) :
尝试使用给定的 email 地址和密码以用户身份登录。
这不会尝试再次创建用户。 如果你想检查用户是否已经存在,你应该在Firestore中添加用户详细信息,例如,并使用我在以下帖子中的解决方案:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.