java - 如何检查用户是否已在 Firebase 中注册?
问题描述
我想验证用户是否已经注册。这是我的代码。请帮忙。谢谢。
fAuth = FirebaseAuth.getInstance();
signUpBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if((validateName()||validateLastName()||validateEmail()||validatePassword()||validateRepeatPassword())!= true){
String email = uEmail.getText().toString().trim();
String password = uPassword.getText().toString().trim();
fAuth.createUserWithEmailAndPassword(email,password);
Toast.makeText(SignUpActivity.this,"Welcome!",Toast.LENGTH_SHORT).show();
openPhoneActivity();
}else {
//here will be toast with something like "You are already registered"
}
}
});
解决方案
该方法createUserWithEmailAndPassword
将检查电子邮件是否已存在于 firebase 身份验证中。从文档:
FirebaseAuthUserCollisionException
如果已经存在具有给定电子邮件地址的帐户,则抛出
您可以使用addOnCompleterListener()
来了解创建是否成功:
auth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (!task.isSuccessful()) {
Toast.makeText((getApplicationContext(), "Authentication failed: " + task.getException().getMessage(),Toast.LENGTH_SHORT).show();
推荐阅读
- git - Git 提取失败,无法读取密码错误
- google-sheets - 谷歌表格,数组公式
- prestashop - Prestashop - 产品页面错误
- python-3.x - 仅在发送和接收时,是否真的需要通过 Lock 序列化套接字?
- azure - Powerapps DropDown Control 问题:使用 Azure 函数中的 text/records/list/DataRows 填充下拉输入控件项
- ios - 在 objc 中使用 swift 框架
- html - 无法从 span itemprop 中提取数据
- facebook-analytics - Facebook 分析是否具有离线功能?
- python - 如何解决 Windows 上的 wsgi_module not found 错误?
- c++ - 没有匹配函数调用类型为 'const std::__1::packaged_task 的对象
',但 `std::is_const` 返回 false