How to create and authenticate email and password in firebase?

Asked

Viewed 787 times

0

I’m taking a class and I try to register the email and password, from this code, in firebase, but it is not created. I can’t get this authentication.

The database I created to test if I was able to "communicate" with firebase and worked accordingly. I already enabled the login by email and password in Firebase settings, but do not show the logins I do.

public class MainActivity extends AppCompatActivity {

    private FirebaseAuth firebaseAuth;

    private DatabaseReference firebaseReferencia = FirebaseDatabase.getInstance().getReference();
    private DatabaseReference usuarioReferencia = firebaseReferencia.child("Usuários");
    private DatabaseReference produtoReferencia = firebaseReferencia.child("Produtos");


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //usuarioReferencia.child("002").child("Nome").setValue("Mariana");

        firebaseAuth = FirebaseAuth.getInstance();

        //Cadastro
        firebaseAuth.createUserWithEmailAndPassword(email, senha)
        .addOnCompleteListener(MainActivity.this, new OnCompleteListener<AuthResult>() {
            @Override
            public void onComplete(@NonNull Task<AuthResult> task) {

                if ( task.isSuccessful() ){//Sucesso ao cadastrar usuario
                    Log.i("CreateUser", "Sucesso ao cadastrar usuário!");
                }else{
                    Log.i("CreateUser", "Erro ao cadastrar usuário!");
                }
            }
        });


    }
}

build.Gradle

dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.gms:google-services:3.2.0'

App

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    compile 'com.google.firebase:firebase-core:12.0.1'
    compile 'com.google.firebase:firebase-auth:12.0.1'
    compile 'com.google.firebase:firebase-database:12.0.1'
    compile 'com.google.android.gms:play-services-auth:12.0.1'
}

apply plugin: 'com.google.gms.google-services'
  • where you’re trying to see if the logins happened?

  • No logcat>Info and firebase.google.com itself

  • you n receive none of the log. i q u put?

  • Change your error log to: Log.i("CreateUser", "Erro ao cadastrar usuário! ", task.getException());, this should show the problem

  • I don’t get either of the two logs. I’ll try this change. may be a problem updating google services?

  • The problem was even outdated google services. I upgraded and created a new emulator and the code ran smooth. Thanks for the help.

Show 1 more comment

1 answer

0

The problem was even outdated google services. I upgraded and created a new emulator and the code ran smooth. Thanks for the help.

Browser other questions tagged

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