[英]How to sign out the user when the email is not verified, Firebase Auth
How to sign out the user when the email is not verified, Firebase Auth, or make an error when trying to sing in and the email is not verified? email未验证,Firebase Auth时如何退出用户,或者email未验证登录时出错?
I use 'com.google.firebase:firebase-auth:19.4.0' Androidx minSdkVersion 21 targetSdkVersion 30 buildToolsVersion "30.0.2"我使用 'com.google.firebase:firebase-auth:19.4.0' Androidx minSdkVersion 21 targetSdkVersion 30 buildToolsVersion "30.0.2"
SingIn_Button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String email = email_login.getText().toString().trim();
String password = password_login.getText().toString().trim();
if (TextUtils.isEmpty(email)) {
email_login.setError("حقل البريد الالكتروني فارغ");
return;
}
if (TextUtils.isEmpty(password)) {
password_login.setError("حقل كلمة المرور فارغ");
return;
}
if (password.length() < 6) {
password_login.setError("يجب ان تكون كلمة المرور اكثر من 6 حروف");
return;
}
progressBar.setVisibility(View.VISIBLE);
mFirebaseAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Toast.makeText(SingInActivity.this, "تم تسجيل الدخول", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(), MainActivity.class));
finish();
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
} else {
Toast.makeText(SingInActivity.this, "خطأ :" + task.getException().getMessage(), Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.GONE);
}
}
});
}
});
Please Help And Thank You All请帮忙,谢谢大家
You'll want to check if the user has verified their email address with:您需要检查用户是否已通过以下方式验证其 email 地址:
mFirebaseAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Toast.makeText(SingInActivity.this, "تم تسجيل الدخول", Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.GONE);
if (!task.getResult().getUser().isEmailVerified()) {
...
}
}
}
});
If you want to sign the user out, that'd be task.getResult().getUser().signOut()
.如果您想将用户注销,那就是
task.getResult().getUser().signOut()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.