Bird
Raised Fist0
Firebasecloud~20 mins

Anonymous authentication in Firebase - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Anonymous Authentication Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ service_behavior
intermediate
2:00remaining
What happens after anonymous sign-in in Firebase?
When a user signs in anonymously using Firebase Authentication, what is the state of the user's identity immediately after sign-in?
Firebase
firebase.auth().signInAnonymously().then(userCredential => {
  console.log(userCredential.user.uid);
});
AThe user is signed out immediately after sign-in.
BThe user has a unique user ID but no email or password associated.
CThe user is signed in with a Google account by default.
DThe user is signed in with a temporary email and password.
Attempts:
2 left
💡 Hint
Think about what anonymous means in authentication.
❓ security
intermediate
2:00remaining
What is a security risk of anonymous authentication?
Which of the following is a potential security risk when using Firebase anonymous authentication in an app?
AAnonymous authentication requires users to enter a password.
BAnonymous users can access admin-only data by default.
CUsers can lose their data if they uninstall the app without linking their account.
DAnonymous users are automatically upgraded to full accounts.
Attempts:
2 left
💡 Hint
Consider what happens if the anonymous user identity is lost.
❓ Configuration
advanced
2:00remaining
Which Firebase rule allows anonymous users to read data but not write?
Given Firebase Realtime Database rules, which rule snippet correctly allows anonymous users to read data but prevents them from writing?
A
{
  "rules": {
    ".read": "auth != null",
    ".write": "auth != null && auth.isAnonymous == false"
  }
}
B
{
  "rules": {
    ".read": "auth != null && auth.isAnonymous == true",
    ".write": "auth != null"
  }
}
C
{
  "rules": {
    ".read": "auth == null",
    ".write": "auth == null"
  }
}
D
{
  "rules": {
    ".read": "true",
    ".write": "false"
  }
}
Attempts:
2 left
💡 Hint
Check the conditions for read and write permissions based on auth state.
❓ Architecture
advanced
2:00remaining
How to preserve user data when upgrading anonymous users?
What is the recommended approach to keep user data when an anonymous Firebase user upgrades to a permanent account?
ASign out the anonymous user and sign in with the new account without linking.
BCreate a new user and manually copy data from the anonymous user ID to the new user ID.
CDelete the anonymous user and create a new permanent user without data migration.
DLink the anonymous user credential to the new permanent credential using linkWithCredential().
Attempts:
2 left
💡 Hint
Think about how Firebase supports account linking.
🧠 Conceptual
expert
2:00remaining
What is the behavior of Firebase anonymous authentication token expiration?
Which statement correctly describes the token expiration behavior for Firebase anonymous authentication users?
AAnonymous user tokens expire after one hour and are automatically refreshed by the SDK.
BAnonymous user tokens expire immediately after sign-in.
CAnonymous user tokens expire after 24 hours and require manual refresh by the developer.
DAnonymous user tokens never expire and do not require refresh.
Attempts:
2 left
💡 Hint
Consider how Firebase handles token lifecycle for all users.

Practice

(1/5)
1. What is the main purpose of Firebase anonymous authentication?
easy
A. Store user data permanently without authentication
B. Require users to verify their email before using the app
C. Allow users to use the app without creating an account
D. Force users to sign in with Google or Facebook

Solution

  1. Step 1: Understand anonymous authentication concept

    Anonymous authentication lets users access the app without signing up or providing credentials.
  2. Step 2: Identify the purpose

    This reduces signup friction and improves user experience by creating a temporary user ID.
  3. Final Answer:

    Allow users to use the app without creating an account -> Option C
  4. Quick Check:

    Anonymous authentication = Allow use without account [OK]
Hint: Anonymous means no signup needed to start [OK]
Common Mistakes:
  • Thinking anonymous auth requires email verification
  • Confusing anonymous auth with social login
  • Assuming anonymous users have permanent accounts
2. Which Firebase method is used to sign in anonymously in JavaScript?
easy
A. firebase.auth().signInWithEmailAndPassword()
B. firebase.auth().signOut()
C. firebase.auth().createUserWithEmailAndPassword()
D. firebase.auth().signInAnonymously()

Solution

  1. Step 1: Recall Firebase anonymous sign-in method

    The correct method to sign in anonymously is signInAnonymously().
  2. Step 2: Eliminate other methods

    Other methods are for email/password sign-in or sign-out, not anonymous sign-in.
  3. Final Answer:

    firebase.auth().signInAnonymously() -> Option D
  4. Quick Check:

    Anonymous sign-in method = signInAnonymously() [OK]
Hint: Anonymous sign-in uses signInAnonymously() method [OK]
Common Mistakes:
  • Using email/password sign-in methods for anonymous login
  • Confusing createUserWithEmailAndPassword with anonymous sign-in
  • Trying to sign out instead of sign in
3. What will the following JavaScript code output if anonymous sign-in succeeds?
firebase.auth().signInAnonymously()
  .then(() => console.log('User ID:', firebase.auth().currentUser.uid))
  .catch(error => console.log('Error:', error.message))
medium
A. User ID: undefined
B. User ID: a unique temporary ID string
C. Error: User not signed in
D. User ID: null

Solution

  1. Step 1: Understand signInAnonymously success behavior

    On success, Firebase creates a temporary user with a unique ID accessible via currentUser.uid.
  2. Step 2: Analyze console.log output

    The code logs 'User ID:' followed by the unique temporary ID string.
  3. Final Answer:

    User ID: a unique temporary ID string -> Option B
  4. Quick Check:

    Anonymous sign-in returns unique temp ID [OK]
Hint: Success logs unique temporary user ID [OK]
Common Mistakes:
  • Expecting undefined or null user ID after sign-in
  • Assuming error message on success
  • Confusing currentUser.uid with email or password
4. Identify the error in this Firebase anonymous sign-in code snippet:
firebase.auth().signInAnonymously
  .then(() => console.log('Signed in anonymously'))
  .catch(error => console.log(error))
medium
A. Missing parentheses after signInAnonymously
B. Incorrect use of .then() method
C. No catch block for errors
D. Using console.log inside then block

Solution

  1. Step 1: Check method call syntax

    The method signInAnonymously must be called with parentheses ().
  2. Step 2: Identify missing parentheses

    The code uses signInAnonymously without parentheses, so it does not invoke the function.
  3. Final Answer:

    Missing parentheses after signInAnonymously -> Option A
  4. Quick Check:

    Method calls need () to execute [OK]
Hint: Always add () to call functions [OK]
Common Mistakes:
  • Forgetting parentheses on method calls
  • Misplacing .then() or .catch() chaining
  • Assuming console.log causes errors
5. You want to let users start anonymously but later upgrade to email/password without losing data. Which Firebase feature helps achieve this?
hard
A. Linking anonymous user to email/password credential
B. Deleting anonymous user and creating new account
C. Signing out anonymous user before email sign-up
D. Using separate Firebase projects for anonymous and email users

Solution

  1. Step 1: Understand user upgrade process

    Firebase allows linking an anonymous user to an email/password credential to keep the same user ID and data.
  2. Step 2: Evaluate options

    Deleting or signing out loses data; separate projects complicate management.
  3. Final Answer:

    Linking anonymous user to email/password credential -> Option A
  4. Quick Check:

    Link anonymous to email to keep data [OK]
Hint: Link accounts to upgrade without losing data [OK]
Common Mistakes:
  • Deleting anonymous user before upgrade
  • Signing out instead of linking accounts
  • Using multiple projects unnecessarily
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard