Challenge - 5 Problems
Firebase Auth Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What happens when a user tries to sign in with an invalid email format?
Consider this Flutter code snippet using Firebase Authentication to sign in a user. What will be the app's behavior if the user enters an invalid email format?
Flutter
try { await FirebaseAuth.instance.signInWithEmailAndPassword( email: userEmail, password: userPassword ); print('Sign in successful'); } catch (e) { print('Error: $e'); }
Attempts:
2 left
💡 Hint
Firebase validates email format and throws specific exceptions for invalid inputs.
✗ Incorrect
Firebase Authentication checks the email format and throws a FirebaseAuthException with code 'invalid-email' if the format is wrong. This exception can be caught and handled.
❓ lifecycle
intermediate2:00remaining
When does FirebaseAuth.instance.authStateChanges() emit a new event?
In Flutter, FirebaseAuth provides authStateChanges() stream. When does this stream emit a new event?
Attempts:
2 left
💡 Hint
Think about what changes the authentication state.
✗ Incorrect
The authStateChanges() stream emits a new event whenever the user's sign-in state changes, such as signing in or signing out.
📝 Syntax
advanced2:00remaining
What is the output of this Flutter Firebase sign-up code snippet?
Analyze the following code and select the correct output printed to the console.
Flutter
try { final userCredential = await FirebaseAuth.instance.createUserWithEmailAndPassword( email: 'test@example.com', password: '123' ); print('User ID: ${userCredential.user?.uid}'); } catch (e) { print('Error: $e'); }
Attempts:
2 left
💡 Hint
Firebase requires passwords to be at least 6 characters.
✗ Incorrect
Firebase throws a FirebaseAuthException with code 'weak-password' if the password is less than 6 characters.
advanced
2:00remaining
What happens to the navigation stack after a successful Firebase sign-out?
In a Flutter app, after calling FirebaseAuth.instance.signOut(), what is the best practice for navigation to reflect the signed-out state?
Attempts:
2 left
💡 Hint
Think about preventing the user from returning to authenticated screens after sign-out.
✗ Incorrect
After sign-out, the app should clear the navigation stack and push the login screen as the new root to prevent back navigation to protected screens.
🔧 Debug
expert2:00remaining
Why does this Flutter Firebase sign-in code cause an unhandled exception?
Review the code below. Why does it cause an unhandled exception when the user enters wrong credentials?
Flutter
void signInUser(String email, String password) async { final userCredential = await FirebaseAuth.instance.signInWithEmailAndPassword( email: email, password: password ); print('Signed in: ${userCredential.user?.email}'); } // Called somewhere without try-catch
Attempts:
2 left
💡 Hint
Think about error handling with async calls.
✗ Incorrect
If signInWithEmailAndPassword fails (e.g., wrong password), it throws an exception. Without try-catch, this exception is unhandled and crashes the app.