Complete the code to initialize Firebase Authentication in an Android Kotlin app.
private lateinit var auth: FirebaseAuth
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
auth = FirebaseAuth.[1]()
}You use FirebaseAuth.getInstance() to get the Firebase Authentication object.
Complete the code to sign in a user with email and password using Firebase Authentication.
auth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener { task ->
if (task.[1]()) {
// Sign in success
} else {
// Sign in failed
}
}The isSuccessful() method checks if the sign-in task succeeded.
Fix the error in the code to send a password reset email using Firebase Authentication.
auth.[1](userEmail) .addOnCompleteListener { task -> if (task.isSuccessful) { // Email sent } }
The correct method to send a password reset email is sendPasswordResetEmail().
Fill both blanks to create a new user with email and password and handle success or failure.
auth.[1](email, password) .addOnCompleteListener { task -> if (task.[2]()) { // User created } else { // Creation failed } }
Use createUserWithEmailAndPassword to create a user and check isSuccessful() to confirm success.
Fill all three blanks to get the current user, check if signed in, and get their email.
val user = auth.[1] if (user != null) { val email = user.[2] println("User email: [3]") }
You get the current user with currentUser, access their email property, and print it.