0
0
Firebasecloud~20 mins

Firebase with React - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Firebase React Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
2:00remaining
What happens when you call firebase.auth().signOut() in a React app?

In a React app using Firebase Authentication, what is the immediate effect of calling firebase.auth().signOut()?

AThe user session remains active until the page is refreshed manually.
BThe user is signed out and the authentication state changes to null immediately.
CThe user is signed out only after the Firebase server confirms the request asynchronously.
DThe user token is invalidated but the user remains signed in until the next API call.
Attempts:
2 left
💡 Hint

Think about how Firebase updates the authentication state in real-time.

Configuration
intermediate
2:00remaining
Which Firebase config snippet correctly initializes Firebase in a React app?

Given the Firebase config object, which snippet correctly initializes Firebase in a React app?

Firebase
const firebaseConfig = {
  apiKey: "API_KEY",
  authDomain: "PROJECT_ID.firebaseapp.com",
  projectId: "PROJECT_ID",
  storageBucket: "PROJECT_ID.appspot.com",
  messagingSenderId: "SENDER_ID",
  appId: "APP_ID"
};
A
import firebase from 'firebase';
firebase.initializeApp(firebaseConfig);
B
import firebase from 'firebase/app';
const app = firebase.initializeApp(firebaseConfig);
C
import { initializeApp } from 'firebase/app';
const app = firebase.initializeApp(firebaseConfig);
D
import { initializeApp } from 'firebase/app';
const app = initializeApp(firebaseConfig);
Attempts:
2 left
💡 Hint

Use the modular Firebase SDK syntax for React apps.

Architecture
advanced
2:00remaining
How to architect React components for real-time Firestore data updates?

You want your React app to show live updates from Firestore. Which architecture pattern is best?

AUse Firestore's <code>onSnapshot</code> listener inside a React <code>useEffect</code> hook to update component state.
BFetch Firestore data once on component mount and refresh manually with a button.
CUse Firestore REST API polling every 5 seconds to update React state.
DStore Firestore data in localStorage and update React state from there.
Attempts:
2 left
💡 Hint

Think about how Firestore provides real-time listeners.

security
advanced
2:00remaining
Which Firebase security rule prevents users from reading others' Firestore documents?

Given a Firestore collection users where each document ID is a user UID, which security rule restricts read access so users can only read their own document?

A
match /users/{userId} {
  allow read: if request.auth.uid == userId;
}
B
match /users/{userId} {
  allow read: if request.auth != null;
}
C
match /users/{userId} {
  allow read: if true;
}
D
match /users/{userId} {
  allow read: if request.auth.uid != userId;
}
Attempts:
2 left
💡 Hint

Check how to compare authenticated user ID with document ID.

Best Practice
expert
2:00remaining
What is the best practice for managing Firebase API keys in a React app?

Firebase API keys are visible in the React app bundle. What is the best practice to keep your Firebase project secure?

AEncrypt Firebase API keys in the React app code and decrypt at runtime.
BHide Firebase API keys by storing them in environment variables and never include them in the client bundle.
CRestrict Firebase API keys in the Firebase console by allowed domains and use security rules to protect data.
DUse a backend server to proxy all Firebase requests and keep API keys secret there.
Attempts:
2 left
💡 Hint

Consider how Firebase API keys are designed and what protects your data.