简体   繁体   English

email未验证时如何注销用户,Firebase Auth

[英]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.

相关问题 如何检查用户 email 在没有 currentUser 的情况下是否在 firebase 中得到验证 - how to check is user email verified or not in firebase without currentUser 如何在 Firebase 身份验证上区分电子邮件验证用户和非验证用户? - How to distinguish email-verified user from non-verified user on Firebase Authentication? 如何在客户端验证email是否在firebase中验证? - How to check if email is verified in firebase on client side? Firebase Auth - 没有来自谷歌登录提供商的电子邮件 - Firebase Auth - no email from google sign in provider 如何在验证其 email 后重定向 flutter 中的用户? - How to redirect a user in flutter after verified their email? 使用 Firebase.auth.signOut() 不会将用户完全注销 - Using Firebase.auth.signOut() doesn't sign the user out completely 当用户更新其 email 时,Firebase - Firebase auth onUpdate cloud function for when a user updates their email Firebase-auth/email-change-needs-verification “多因素用户必须始终拥有经过验证的电子邮件” - Firebase-auth/email-change-needs-verification "multifactor users must always have a verified email" Firebase 仪表板组 email 已验证 - Firebase Dashboard set email verified Flutter 集成测试 firebase 身份验证(电子邮件链接或谷歌登录) - Flutter integration test firebase auth (email link or google sign in)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM