I'm trying to do a registration with Firebase and Kotlin. Taking a look to the docs, I see all the examples in Java. So when I try to implement in Kotlin I'm not able to make it work.
In Java is supposed to be like:
// [START create_user_with_email]
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
FirebaseUser user = mAuth.getCurrentUser();
} else {
// If sign in fails, display a message to the user.
......
}
// [START_EXCLUDE]
.......
// [END_EXCLUDE]
}
});
// [END create_user_with_email]
But when I try to implement in kotlin like this:
// [START create_user_with_email]
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, OnCompleteListener<AuthResult> { task ->
if (task.isSuccessful) {
// Sign in success, update UI with the signed-in user's information
val user = mAuth.currentUser
} else {
......
}
// [START_EXCLUDE]
.....
// [END_EXCLUDE]
})
// [END create_user_with_email]
But this, give me an error:
And I don't know how to solve it.
The example is from: https://github.com/firebase/quickstart-android/blob/master/auth/app/src/main/java/com/google/firebase/quickstart/auth/EmailPasswordActivity.java#L119-L137
I have implemented Firebase registration with email and password in the following way and it works:
this.firebaseAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener { task: Task<AuthResult> ->
if (task.isSuccessful) {
//Registration OK
val firebaseUser = this.firebaseAuth.currentUser!!
} else {
//Registration error
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With