React Native Firebase
React Native Firebase Interview with follow-up questions
1. What is Firebase and how can it be used in a React Native application?
Firebase is a Google Backend-as-a-Service (BaaS) that gives mobile/web apps ready-made backend features without you running servers: authentication, Firestore (the preferred database for new apps) and the older Realtime Database, Cloud Storage, Cloud Messaging (FCM) for push, Analytics, Crashlytics, and Cloud Functions.
In React Native you integrate it with React Native Firebase (@react-native-firebase/*), which wraps the native Firebase SDKs for better performance than the pure-JS web SDK. The 2026 detail to get right: v22+ uses the modular API (mirroring Firebase JS SDK v9+) — you call free functions like getAuth() and getFirestore() rather than the deprecated namespaced firebase.auth() style:
import { getApp } from '@react-native-firebase/app';
import { getFirestore, collection, getDocs } from '@react-native-firebase/firestore';
const db = getFirestore(getApp());
const snap = await getDocs(collection(db, 'users'));
Typical RN uses: user auth, real-time data sync, push notifications, and analytics. It works with Expo via config plugins (no manual eject — Expo's CNG/prebuild handles the native setup).
Follow-up 1
Can you explain how to set up Firebase in a React Native project?
To set up Firebase in a React Native project, follow these steps:
- Create a Firebase project in the Firebase console.
- Install the Firebase SDK by running
npm install --save firebasein your project directory. - Import the necessary Firebase modules in your React Native code.
- Initialize Firebase by calling
firebase.initializeApp(config)with your Firebase project configuration. - Use the Firebase services and APIs in your React Native code to handle backend functionalities.
Follow-up 2
What are some of the key features of Firebase that can be beneficial for a React Native app?
Some key features of Firebase that can be beneficial for a React Native app are:
- Real-time Database: Firebase provides a real-time database that allows you to synchronize data between clients in real-time.
- Authentication: Firebase offers built-in authentication methods like email/password, social logins, and more, making it easy to implement user authentication in your React Native app.
- Cloud Storage: Firebase provides cloud storage for storing and serving user-generated content like images, videos, and files.
- Cloud Functions: Firebase allows you to write and deploy serverless functions that can be triggered by events in your app.
- Analytics: Firebase offers powerful analytics tools to track user behavior, app performance, and more.
- Push Notifications: Firebase provides a simple way to send push notifications to your React Native app users.
Follow-up 3
Can you give an example of a real-world application where Firebase can be used in React Native?
One example of a real-world application where Firebase can be used in React Native is a social media app. Firebase's real-time database can be used to store and synchronize user posts, comments, and likes in real-time. Firebase authentication can be used to handle user sign-up and login. Cloud storage can be used to store and serve user profile pictures and other media files. Firebase's push notification feature can be used to send notifications to users when they receive new messages or when there are updates in their social network.
Follow-up 4
How does Firebase handle data synchronization in React Native?
Firebase handles data synchronization in React Native through its real-time database. The real-time database uses a data synchronization protocol called Firebase Realtime Database Sync Protocol, which allows multiple clients to listen for changes to a specific data location and receive updates in real-time. When a client makes a change to the data, Firebase automatically propagates the change to all connected clients, ensuring that the data stays synchronized across all devices. This makes it easy to build real-time collaborative features in React Native apps, such as chat applications, collaborative document editing, and more.
2. How can Firebase Authentication be implemented in a React Native application?
Steps to add Firebase Authentication with React Native Firebase (v22+, modular API):
- Install the packages:
npm install @react-native-firebase/app @react-native-firebase/auth. - Add your Firebase config (
google-services.jsonfor Android,GoogleService-Info.plistfor iOS). On Expo, register the config plugin inapp.jsonand run a prebuild — no manual native edits or eject needed. - Use the modular free functions (not the deprecated
firebase.auth()namespaced API):
import { getApp } from '@react-native-firebase/app';
import {
getAuth, createUserWithEmailAndPassword,
signInWithEmailAndPassword, signOut, onAuthStateChanged,
} from '@react-native-firebase/auth';
const auth = getAuth(getApp());
await createUserWithEmailAndPassword(auth, email, password);
await signInWithEmailAndPassword(auth, email, password);
- Track auth state with
onAuthStateChangedand clean up the subscription so you don't leak listeners:
useEffect(() => {
const unsub = onAuthStateChanged(auth, (user) => setUser(user));
return unsub; // unsubscribe on unmount
}, []);
Gotchas interviewers raise: social/phone sign-in (Google, Apple) needs extra native setup; persist the session yourself only if needed (Firebase persists by default); and never trust the client — enforce access with Firebase Security Rules on the backend.
Follow-up 1
What are the different types of authentication supported by Firebase?
Firebase supports various types of authentication methods, including:
- Email and password authentication: Users can create an account using their email and password.
- Phone number authentication: Users can sign in using their phone number and receive a verification code.
- Google authentication: Users can sign in using their Google account.
- Facebook authentication: Users can sign in using their Facebook account.
- Twitter authentication: Users can sign in using their Twitter account.
- GitHub authentication: Users can sign in using their GitHub account.
These authentication methods can be implemented in a React Native application using the Firebase Authentication API.
Follow-up 2
Can you explain the process of implementing Firebase Google Authentication in React Native?
To implement Firebase Google Authentication in a React Native application, follow these steps:
- Install the necessary dependencies by running the command
npm install @react-native-firebase/app @react-native-firebase/auth @react-native-firebase/google. - Configure Firebase and Google Sign-In in your Firebase project and obtain the necessary configuration files.
- Import the necessary Firebase and Google modules in your React Native component.
- Use the Firebase Authentication method
signInWithGoogleto initiate the Google sign-in process. - Handle the Google sign-in response and authenticate the user using Firebase.
- Implement the necessary UI components and logic to handle the Google sign-in process.
For more detailed information and code examples, you can refer to the official Firebase documentation for React Native.
Follow-up 3
What are the security measures provided by Firebase for authentication?
Firebase provides several security measures for authentication, including:
- Secure transmission: Firebase uses HTTPS to ensure that all authentication requests and responses are encrypted.
- Password hashing: User passwords are securely hashed and stored in Firebase's authentication system.
- Account protection: Firebase offers features like email verification, phone number verification, and reCAPTCHA to protect user accounts from unauthorized access.
- OAuth providers: Firebase supports OAuth providers like Google, Facebook, Twitter, and GitHub, which have their own security measures in place.
- Firebase Security Rules: You can define custom security rules to control access to your Firebase resources.
These security measures help protect user authentication data and prevent unauthorized access to user accounts.
Follow-up 4
How can we handle user sessions using Firebase Authentication in React Native?
Firebase Authentication handles user sessions automatically by providing an authentication state listener. You can use the onAuthStateChanged method provided by Firebase to listen for changes in the user's authentication state.
Here's an example of how you can handle user sessions using Firebase Authentication in React Native:
import React, { useEffect, useState } from 'react';
import { View, Text } from 'react-native';
import auth from '@react-native-firebase/auth';
const App = () => {
const [user, setUser] = useState(null);
useEffect(() => {
const unsubscribe = auth().onAuthStateChanged((user) => {
setUser(user);
});
return unsubscribe;
}, []);
return (
{user ? Welcome, {user.email} : Please sign in}
);
};
export default App;
In this example, the onAuthStateChanged method is used to update the user state whenever the user's authentication state changes. The UI is then updated based on the user's authentication status.
For more information on handling user sessions with Firebase Authentication in React Native, you can refer to the official Firebase documentation.
3. How can Firebase Cloud Messaging (FCM) be used in a React Native application?
Firebase Cloud Messaging (FCM) sends push notifications to Android and iOS. With React Native Firebase (v22+, modular API) the flow is:
- Set up the Firebase project, enable FCM, and on iOS configure the APNs key/cert and Push Notifications capability (the common gotcha — iOS won't deliver without APNs).
- Install
@react-native-firebase/appand@react-native-firebase/messaging. - Request permission (required on iOS and on Android 13+), then get the device token to target the device:
import { getApp } from '@react-native-firebase/app';
import { getMessaging, requestPermission, getToken, onMessage }
from '@react-native-firebase/messaging';
const messaging = getMessaging(getApp());
await requestPermission(messaging);
const token = await getToken(messaging); // send to your server
- Handle messages in each app state:
- Foreground:
onMessage(messaging, msg => ...)— note FCM does not auto-display a banner in the foreground, so render a local notification (e.g. Notifee) yourself. - Background/quit:
setBackgroundMessageHandler(registered at the app's entry, outside the component tree). - Notification taps:
getInitialNotification/onNotificationOpenedAppfor deep linking.
- Foreground:
Interviewer follow-ups: foreground vs background handling, the APNs requirement on iOS, token refresh (onTokenRefresh), and data-only vs notification messages.
Follow-up 1
What are the steps to integrate Firebase Cloud Messaging in a React Native app?
To integrate Firebase Cloud Messaging (FCM) in a React Native app, you need to follow these steps:
- Set up a Firebase project and enable FCM for your app.
- Install the necessary dependencies by running the following command:
npm install @react-native-firebase/app @react-native-firebase/messaging
- Configure the Firebase SDK by adding the necessary code to your
index.jsfile. - Request permission from the user to receive push notifications using the
messaging().requestPermission()method. - Handle incoming push notifications by subscribing to the
onMessageevent using themessaging().onMessage()method.
By following these steps, you can successfully integrate FCM into your React Native app.
Follow-up 2
How can we handle push notifications using FCM in React Native?
To handle push notifications using Firebase Cloud Messaging (FCM) in React Native, you need to:
- Request permission from the user to receive push notifications using the
messaging().requestPermission()method. - Handle incoming push notifications by subscribing to the
onMessageevent using themessaging().onMessage()method. - Perform the desired actions when a push notification is received.
Here's an example of how to handle push notifications in React Native using FCM:
import messaging from '@react-native-firebase/messaging';
messaging().requestPermission().then(() => {
messaging().onMessage((remoteMessage) => {
// Handle incoming push notification
console.log('Received a new push notification:', remoteMessage);
// Perform the desired actions
});
});
By implementing these steps, you can handle push notifications in your React Native app using FCM.
Follow-up 3
Can you explain how to send a push notification to a specific user using FCM in React Native?
To send a push notification to a specific user using Firebase Cloud Messaging (FCM) in React Native, you need to:
- Retrieve the FCM token of the user you want to send the notification to.
- Use the FCM token to send a push notification from your server or Firebase console.
Here's an example of how to send a push notification to a specific user using FCM in React Native:
import messaging from '@react-native-firebase/messaging';
const userFCMToken = 'USER_FCM_TOKEN'; // Replace with the FCM token of the user
messaging().sendMessage({
data: {
title: 'New Message',
body: 'You have a new message!',
},
token: userFCMToken,
});
By following these steps, you can send a push notification to a specific user using FCM in your React Native app.
Follow-up 4
What are the limitations of using FCM in React Native?
While Firebase Cloud Messaging (FCM) is a powerful tool for sending push notifications in React Native, it has some limitations:
- FCM requires a network connection to send and receive push notifications. If the device is offline, the push notification will not be delivered.
- FCM does not guarantee the delivery of push notifications. There may be cases where a push notification is not delivered to the device.
- FCM has limitations on the payload size of push notifications. The payload size should not exceed 4KB for Android and 2KB for iOS.
- FCM does not provide built-in support for scheduled or recurring push notifications. You need to implement this functionality on your server or use a third-party service.
It's important to consider these limitations when using FCM in your React Native app and plan your push notification strategy accordingly.
4. How can Firebase Realtime Database be used in a React Native application?
To use Firebase Realtime Database in React Native, use React Native Firebase (v22+) with its modular API — not the bare firebase web SDK, and not the deprecated namespaced firebase.database() style. (Note: for new apps, Firestore is usually the better choice — richer queries and scaling; mention Realtime Database when you need simple, low-latency JSON sync or presence.)
- Install
@react-native-firebase/appand@react-native-firebase/database. - Add the native config files (or the Expo config plugin + prebuild).
- Read/write with the modular free functions:
import React, { useEffect, useState } from 'react';
import { View, Text } from 'react-native';
import { getApp } from '@react-native-firebase/app';
import { getDatabase, ref, onValue, set } from '@react-native-firebase/database';
const App = () => {
const [data, setData] = useState(null);
useEffect(() => {
const db = getDatabase(getApp());
const dataRef = ref(db, 'data');
const unsub = onValue(dataRef, (snapshot) => setData(snapshot.val()));
return () => unsub(); // detach listener on unmount
}, []);
// set(ref(getDatabase(getApp()), 'data'), 'hello');
return (
{data ? String(data) : 'loading…'}
);
};
export default App;
Gotchas: always detach listeners to avoid leaks, secure access with Realtime Database Security Rules (the client config is public), and remember reads are real-time subscriptions, not one-off fetches (use get for that).
Follow-up 1
Can you explain the structure of Firebase Realtime Database?
Firebase Realtime Database is a NoSQL cloud-hosted database that stores data as JSON. It has a hierarchical structure where data is organized into a tree-like structure of key-value pairs. Each key in the database is a unique identifier, and the corresponding value can be a string, number, boolean, object, or an array.
Here is an example of the structure of a Firebase Realtime Database:
{
"users": {
"user1": {
"name": "John",
"age": 25
},
"user2": {
"name": "Jane",
"age": 30
}
}
}
Follow-up 2
How can we perform CRUD operations using Firebase Realtime Database in React Native?
Firebase Realtime Database provides several methods to perform CRUD (Create, Read, Update, Delete) operations:
Create: To create new data, you can use the
set()method to set the value of a specific key in the database.Read: To read data, you can use the
on()method to listen for changes in the database and retrieve the data using thesnapshotobject.Update: To update existing data, you can use the
update()method to update the value of a specific key in the database.Delete: To delete data, you can use the
remove()method to remove a specific key and its corresponding value from the database.
Here is an example of how to perform CRUD operations using Firebase Realtime Database in React Native:
// Create
database.ref('users/user1').set({
name: 'John',
age: 25
});
// Read
database.ref('users').on('value', (snapshot) => {
const users = snapshot.val();
console.log(users);
});
// Update
database.ref('users/user1').update({
age: 30
});
// Delete
database.ref('users/user1').remove();
Follow-up 3
What are the advantages of using Firebase Realtime Database over traditional databases?
Firebase Realtime Database offers several advantages over traditional databases:
Real-time synchronization: Firebase Realtime Database automatically synchronizes data across all connected devices in real-time, providing a seamless and responsive user experience.
No server-side code required: Firebase Realtime Database is a cloud-hosted database, which means you don't need to set up and maintain a server to handle database operations. Firebase takes care of the server-side infrastructure for you.
Scalability: Firebase Realtime Database scales automatically to handle any amount of data and traffic, ensuring that your application remains performant even under heavy load.
Offline support: Firebase Realtime Database provides offline support, allowing your application to continue functioning even when the device is offline. Data changes made offline are automatically synchronized when the device comes back online.
Easy integration with other Firebase services: Firebase Realtime Database seamlessly integrates with other Firebase services like Firebase Authentication, Firebase Cloud Messaging, and Firebase Storage, making it easy to build a complete backend for your application.
Follow-up 4
How does Firebase Realtime Database handle data synchronization in React Native?
Firebase Realtime Database handles data synchronization in React Native through its real-time synchronization feature. When you listen for changes in the database using the on() method, Firebase establishes a persistent connection between the client and the server. Any changes made to the data in the database are automatically synchronized across all connected devices in real-time.
Here's how the data synchronization process works:
When a change is made to the data in the database, Firebase sends a notification to all connected devices that have registered listeners for that data.
The client devices receive the notification and update their local copies of the data accordingly.
The React Native application can then update its UI based on the updated data.
This real-time synchronization ensures that all connected devices have the latest version of the data and allows for real-time collaboration and updates in your React Native application.
5. How can Firebase Analytics be used in a React Native application?
Firebase Analytics gives you event and user-behavior tracking with minimal setup. With React Native Firebase (v22+, modular API):
- Install
@react-native-firebase/appand@react-native-firebase/analytics. - Add the native config files (or Expo config plugin + prebuild). On iOS, some data needs App Tracking Transparency consent.
- Log events and set user properties via the modular functions:
import { getApp } from '@react-native-firebase/app';
import { getAnalytics, logEvent, setUserProperty, logScreenView }
from '@react-native-firebase/analytics';
const analytics = getAnalytics(getApp());
await logEvent(analytics, 'add_to_cart', { item_id: 'SKU_123', value: 9.99 });
await setUserProperty(analytics, 'plan', 'pro');
await logScreenView(analytics, { screen_name: 'Checkout', screen_class: 'CheckoutScreen' });
- View results in the Firebase console (DebugView for live testing, then the Analytics dashboards).
Interviewer follow-ups: use Firebase's predefined event names where they exist (better reporting), automatic screen tracking vs manual logScreenView with React Navigation, the DebugView for verifying events during development, and privacy/consent (ATT on iOS, opt-out via setAnalyticsCollectionEnabled).
Follow-up 1
What kind of data can be tracked using Firebase Analytics?
Firebase Analytics allows you to track various types of data in a React Native app, including:
Events: You can track custom events to measure user interactions, such as button clicks, screen views, and in-app purchases.
User properties: You can define user properties to segment and analyze your users, such as age, gender, and location.
Conversions: You can track conversion events to measure the effectiveness of your marketing campaigns, such as app installs and in-app purchases.
User engagement: Firebase Analytics provides metrics like session duration, screen views, and user retention to measure user engagement with your app.
Follow-up 2
What are the steps to integrate Firebase Analytics in a React Native app?
To integrate Firebase Analytics in a React Native app, follow these steps:
Install the Firebase SDK: Install the Firebase SDK using npm or yarn.
Set up Firebase project: Create a new Firebase project or use an existing one.
Configure Firebase in your app: Add the Firebase configuration to your React Native app.
Initialize Firebase Analytics: Initialize Firebase Analytics in your app.
Track events: Use the Firebase Analytics API to track events and user properties.
View analytics data: Use the Firebase console to view and analyze the analytics data collected from your app.
Follow-up 3
How can Firebase Analytics help in understanding user behavior in a React Native app?
Firebase Analytics can help in understanding user behavior in a React Native app by providing insights into how users interact with your app. It allows you to:
Track user actions: You can track events and user properties to understand how users navigate through your app and interact with different features.
Analyze user engagement: Firebase Analytics provides metrics like session duration, screen views, and user retention to measure user engagement and identify areas for improvement.
Segment users: You can define user properties to segment your users and analyze their behavior based on different criteria, such as age, gender, and location.
Measure conversions: You can track conversion events to measure the effectiveness of your marketing campaigns and understand how users convert in your app.
Follow-up 4
What are the limitations of using Firebase Analytics in React Native?
There are a few limitations of using Firebase Analytics in React Native:
Limited event parameters: Firebase Analytics allows a maximum of 25 event parameters per event, and each parameter can have a maximum length of 100 characters.
Limited user properties: Firebase Analytics allows a maximum of 25 user properties per app, and each property can have a maximum length of 36 characters.
Limited reporting granularity: Firebase Analytics provides aggregated data and does not offer detailed individual user-level data.
Limited data retention: Firebase Analytics retains data for a maximum of 60 days, so historical data beyond that period is not available.
Limited attribution capabilities: Firebase Analytics has limited attribution capabilities compared to other attribution platforms, which may affect the accuracy of campaign measurement.
Live mock interview
Mock interview: React Native Firebase
- Read your scene and goals
- Talk it out; goals tick off live
- Get a score and stronger lines
Your voice and your AI key never touch our servers; the key stays in this browser and is sent only to Google. Only your round scores are saved to track progress.