0
0
iOS Swiftmobile~10 mins

Firebase Authentication in iOS Swift - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Firebase Authentication module in Swift.

iOS Swift
import [1]
Drag options to blanks, or click blank then click option'
AFoundation
BFirebaseAuth
CUIKit
DSwiftUI
Attempts:
3 left
💡 Hint
Common Mistakes
Importing UIKit or Foundation instead of FirebaseAuth.
Forgetting to import any Firebase module.
2fill in blank
medium

Complete the code to sign in a user with email and password using Firebase Authentication.

iOS Swift
Auth.auth().signIn(withEmail: email, password: password) { authResult, error in
  if let error = [1] {
    print("Error signing in: \(error.localizedDescription)")
  } else {
    print("User signed in successfully")
  }
}
Drag options to blanks, or click blank then click option'
Aerror
BauthResult
Cpassword
Demail
Attempts:
3 left
💡 Hint
Common Mistakes
Checking the wrong variable for errors.
Not handling the error case at all.
3fill in blank
hard

Fix the error in the code to create a new user with email and password.

iOS Swift
Auth.auth().createUser(withEmail: email, password: password) { [1], error in
  if let error = error {
    print("Failed to create user: \(error.localizedDescription)")
  } else {
    print("User created successfully")
  }
}
Drag options to blanks, or click blank then click option'
Aresult
Buser
Cerror
DauthResult
Attempts:
3 left
💡 Hint
Common Mistakes
Using user or result instead of authResult.
Confusing the error parameter with the first parameter.
4fill in blank
hard

Fill both blanks to send a password reset email to the user.

iOS Swift
Auth.auth().[1](withEmail: email) { error in
  if let [2] = error {
    print("Failed to send reset email: \(error.localizedDescription)")
  } else {
    print("Password reset email sent")
  }
}
Drag options to blanks, or click blank then click option'
AsendPasswordReset
BresetPassword
Cerror
Dfailure
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong method name like resetPassword.
Using a different variable name than error.
5fill in blank
hard

Fill all three blanks to check if a user is currently signed in and print their email.

iOS Swift
if let user = Auth.auth().[1] {
  let email = user.[2]
  print("Signed in user email: \(email)")
} else {
  print("No user is signed in")
}

// To sign out the user:
try? Auth.auth().[3]()
Drag options to blanks, or click blank then click option'
AcurrentUser
Bemail
CsignOut
DuserEmail
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method instead of property for current user.
Accessing a non-existent property like userEmail.
Forgetting to handle sign out with try/catch.