Firebaseuth stopped authenticating the user

Asked

Viewed 185 times

0

In the app, before the user sign in, they need to log in with email and password. If you don’t have it you can create an account.

The problem happened last night, already registered users can not log more and gives no error. But if I create a new account, on this screen I programmed that once the registration is done already log in the app.

The problem seems to be the login screen. In my lopcat appears this

D/FirebaseAuth: Notifying id token listeners about user ( 7zWrS3nX2lW815oOMzwoxyFRbzc2 ).
D/FirebaseApp: Notifying auth state listeners.
D/FirebaseApp: Notified 0 auth state listeners.

If I put wrong password or wrong email it is no longer checking either, being that days ago was working normally.

My login screen

    public class TeladeLoginActivity extends AppCompatActivity {

    private EditText edt_Email;
    private EditText edt_Senha;
    private TextView txt_CriarConta;
    private Button btn_Logar;
    private ProgressBar progressBarLogin;

    ValidaEmail validaEmail;
    private FirebaseAuth autenticacao;
    VerificaInternet verificaInternet;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_telade_login);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().hide();

        edt_Email = (EditText) findViewById(R.id.edt_TelaLogin_Email);
        edt_Senha = (EditText) findViewById(R.id.edt_TelaLogin_Password);
        txt_CriarConta = (TextView) findViewById(R.id.txt_CriarUmaConta);
        btn_Logar = (Button) findViewById(R.id.btn_LogarApp);
        progressBarLogin = (ProgressBar) findViewById(R.id.progressBarLogin);

        verificaInternet = new VerificaInternet(this);
        validaEmail = new ValidaEmail();

        btn_Logar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (edt_Email.getText().toString().isEmpty() ||
                        edt_Senha.getText().toString().isEmpty()) {
                    Toast.makeText(TeladeLoginActivity.this, "Campos não podem ficar vazios",
                            Toast.LENGTH_SHORT).show();

                }else if (!validaEmail.validar(edt_Email.getText().toString())){
                    edt_Senha.setError("Verifique o email digitado");

                }else {

                    String emailUsuario = edt_Email.getText().toString().trim();
                    String senhaUsuario = edt_Senha.getText().toString().trim();
                    criarUser(emailUsuario, senhaUsuario);
                }

            }
        });


        txt_CriarConta.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent cadastrarUsuario = new Intent(TeladeLoginActivity.this, CadastrarContaActivity.class);
                startActivity(cadastrarUsuario);

            }
        });

    }

    @Override
    protected void onStart() {
        super.onStart();
        autenticacao = AutenticacaoLogin.getFirebaseAuth();
    }

    private void criarUser(String emailUsuario, final String senhaUsuario) {
       // progressBarLogin.setVisibility(View.VISIBLE);
        autenticacao.signInWithEmailAndPassword(
                emailUsuario, senhaUsuario
        ).addOnCompleteListener(TeladeLoginActivity.this, new OnCompleteListener<AuthResult>() {
            @Override
            public void onComplete(@NonNull Task<AuthResult> task) {

                if (verificaInternet.existeConexao()){


                }else if (task.isSuccessful()) {

                    progressBarLogin.setVisibility(View.INVISIBLE);
                    Intent abrirApp = new Intent(TeladeLoginActivity.this, MainActivity.class);
                    startActivity(abrirApp);

                } else {
                    progressBarLogin.setVisibility(View.INVISIBLE);
                    String erroExcecao = "";

                    try {
                        throw task.getException();

                    } catch (FirebaseAuthInvalidCredentialsException e) {
                        erroExcecao = "Email inválido";

                    } catch (FirebaseAuthUserCollisionException e) {

                        erroExcecao = "Esse e-mail já está em uso no App.";

                    } catch (Exception e) {

                        if (senhaUsuario.length() < 6) {
                            edt_Senha.setText("");//Limpa o campo de texto para o usuário digitar uma nova senha mais forte
                            edt_Senha.requestFocus();//Seta o focus no campo de texto
                            Toast.makeText(TeladeLoginActivity.this, "Senha incorreta", Toast.LENGTH_LONG).show();
                        }
                        erroExcecao = "Erro ao logar no aplicativo.";
                        e.printStackTrace();
                    }

                    Toast.makeText(TeladeLoginActivity.this, "Erro: " + erroExcecao, Toast.LENGTH_LONG).show();

                }
            }
        });
    }
}

1 answer

0

I noticed now that in Activity of registering user, there is no test of whether the device is connected on the internet. Already on the Login screen has this check. What I did was remove it and add at the end of the last catch.

if (task.isSuccessful()) {

                progressBarLogin.setVisibility(View.INVISIBLE);
                Intent abrirApp = new Intent(TeladeLoginActivity.this, MainActivity.class);
                startActivity(abrirApp);

            } else {
                progressBarLogin.setVisibility(View.INVISIBLE);
                String erroExcecao = "";

                try {
                    throw task.getException();

                } catch (FirebaseAuthInvalidCredentialsException e) {
                    erroExcecao = "Email ou senha inválidos";

                } catch (FirebaseAuthUserCollisionException e) {

                    erroExcecao = "Esse e-mail já está em uso no App.";

                } catch (FirebaseAuthEmailException e) {
                    erroExcecao = "Erro na autenticacao do email";

                } catch (Exception e) {

                    if (senhaUsuario.length() < 6) {
                        edt_Senha.setText("");//Limpa o campo de texto para o usuário digitar uma nova senha mais forte
                        edt_Senha.requestFocus();//Seta o focus no campo de texto
                        Toast.makeText(TeladeLoginActivity.this, "Senha incorreta", Toast.LENGTH_LONG).show();
                    }
                    erroExcecao = "Erro ao logar no aplicativo. Verifique se está conectado a internet";
                    e.printStackTrace();
                }

                Toast.makeText(TeladeLoginActivity.this, erroExcecao, Toast.LENGTH_LONG).show();

            }
        }
    });
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.