0
0
iOS Swiftmobile~20 mins

Firebase Authentication in iOS Swift - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Firebase Auth Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What happens after a successful Firebase email/password sign-in?
Consider this Swift code snippet for Firebase Authentication sign-in:
Auth.auth().signIn(withEmail: email, password: password) { authResult, error in
  if let user = authResult?.user {
    print("User signed in: \(user.email ?? "unknown")")
  } else {
    print("Sign-in failed")
  }
}

What will be printed if the sign-in is successful?
iOS Swift
Auth.auth().signIn(withEmail: email, password: password) { authResult, error in
  if let user = authResult?.user {
    print("User signed in: \(user.email ?? \"unknown\")")
  } else {
    print("Sign-in failed")
  }
}
AUser signed in: user@example.com
BSign-in failed
CUser signed in: unknown
DNo output printed
Attempts:
2 left
💡 Hint
Check what the 'user.email' property contains after successful sign-in.
🧠 Conceptual
intermediate
1:30remaining
What error is returned if Firebase sign-in is attempted with wrong password?
In Firebase Authentication for iOS, if a user tries to sign in with an email that exists but enters the wrong password, what error code will the completion handler receive?
AAuthErrorCode.networkError
BAuthErrorCode.userNotFound
CAuthErrorCode.invalidEmail
DAuthErrorCode.wrongPassword
Attempts:
2 left
💡 Hint
Think about the error that specifically means the password is incorrect.
lifecycle
advanced
2:00remaining
When is the Firebase Auth state listener triggered?
Given this Swift code:
Auth.auth().addStateDidChangeListener { auth, user in
  if let user = user {
    print("User is signed in: \(user.uid)")
  } else {
    print("No user signed in")
  }
}

At which moments will this listener be called?
iOS Swift
Auth.auth().addStateDidChangeListener { auth, user in
  if let user = user {
    print("User is signed in: \(user.uid)")
  } else {
    print("No user signed in")
  }
}
AOnly when the user signs in
BWhen the app starts and whenever the user signs in or out
COnly when the user signs out
DOnly when the app is terminated
Attempts:
2 left
💡 Hint
Think about when the authentication state changes.
📝 Syntax
advanced
2:00remaining
What is the correct way to create a new Firebase user with email and password?
Which of the following Swift code snippets correctly creates a new user with Firebase Authentication?
A
Auth.auth().createUser(withEmail: email, password: password) { authResult, error in
  if let user = authResult?.user {
    print("User created: \(user.email ?? "")")
  }
}
B
Auth.auth().signUp(withEmail: email, password: password) { authResult, error in
  print("User created")
}
C
Auth.auth().createUser(email: email, password: password) { authResult, error in
  print("User created")
}
D
Auth.createUser(withEmail: email, password: password) { user, error in
  print("User created")
}
Attempts:
2 left
💡 Hint
Check the exact method name and parameters in Firebase iOS SDK.
🔧 Debug
expert
2:30remaining
Why does this Firebase sign-out code cause a crash?
Consider this Swift code snippet:
try? Auth.auth().signOut()
print("User signed out")

Sometimes this code crashes the app. What is the most likely cause?
iOS Swift
try? Auth.auth().signOut()
print("User signed out")
AFirebase requires a completion handler for signOut()
BThe print statement is called before signOut completes
CThe signOut() method can throw an error that is not handled properly
DThe Auth object is nil causing a crash
Attempts:
2 left
💡 Hint
Check how Swift handles errors from throwing functions.