Challenge - 5 Problems
Firebase Auth Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What happens after a successful Firebase email/password sign-in?
Consider this Swift code snippet for Firebase Authentication sign-in:
What will be printed if the sign-in is successful?
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")
}
}Attempts:
2 left
💡 Hint
Check what the 'user.email' property contains after successful sign-in.
✗ Incorrect
When sign-in succeeds, 'authResult?.user' is non-nil and 'user.email' contains the signed-in user's email. The print statement outputs that email.
🧠 Conceptual
intermediate1: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?
Attempts:
2 left
💡 Hint
Think about the error that specifically means the password is incorrect.
✗ Incorrect
Firebase returns 'AuthErrorCode.wrongPassword' when the password does not match the stored password for the email.
❓ lifecycle
advanced2:00remaining
When is the Firebase Auth state listener triggered?
Given this Swift code:
At which moments will this listener be called?
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")
}
}Attempts:
2 left
💡 Hint
Think about when the authentication state changes.
✗ Incorrect
The listener triggers immediately on adding and whenever the user signs in or out, reflecting current auth state.
📝 Syntax
advanced2: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?
Attempts:
2 left
💡 Hint
Check the exact method name and parameters in Firebase iOS SDK.
✗ Incorrect
The correct method is 'createUser(withEmail:password:completion:)' on 'Auth.auth()'. Other options use wrong method names or signatures.
🔧 Debug
expert2:30remaining
Why does this Firebase sign-out code cause a crash?
Consider this Swift code snippet:
Sometimes this code crashes the app. What is the most likely cause?
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")
Attempts:
2 left
💡 Hint
Check how Swift handles errors from throwing functions.
✗ Incorrect
signOut() is a throwing method. Using 'try?' ignores errors but if an error occurs, it can cause unexpected behavior or crash if not handled properly.