Build a Complete Secure Chat APP using Firebase and React Native & Expo

Signal Clone

Rohit Kumar Thakur
3 min readFeb 22, 2024
Chat App With Firebase And React Native Expo

Hello everyone, My name is Rohit. In this article, I will guide you through how to build a complete secure chat app using Firebase and React Native & Expo. You’ll learn how to implement features like phone number authentication, user profiles, chat screens, and real-time messaging. By the end, you’ll have a working app you can showcase and customize further! If you face any issues then feel free to comment or DM me on my social media handles. X && Instagram

Let’s see what we’ll build. Users will enter their phone number, verify with a code, and create a profile if new. Logged-in users can browse a user list and chat with each other seamlessly. Finally, they can logout when they’re done.

Setting Up the Project:

  1. Initialize Expo Project: Choose a template and name your app (e.g., “chatapp”). Install necessary dependencies and set up React Navigation for smooth transitions.
  2. Firebase Setup: Create a Firebase project, enable phone authentication and Firestore database. Obtain Android SHA-1 keys and configure them in both Firebase and your app.json file.
  3. Project Structure: Create folders for components, navigation, utils, and assets. Each component will handle specific parts of the app (e.g., Login, Dashboard, Chat).

Building the Login Screen:

  1. Import Modules: Include React, React Native, Firebase, and React Navigation for state management, authentication, and navigation.
  2. State Variables: Define variables for phone number, verification code, and confirmation object.
  3. Phone Number Verification: Handle input validation and send verification code using Firebase’s signInWithPhoneNumber method.
  4. Code Confirmation: Verify the provided code and navigate to the appropriate screen based on user existence (Dashboard for existing users, Detail screen for new users)
  5. User Interface: Design a user-friendly interface with input fields, buttons, and error messages.

Building the Detail Screen:

  1. Capture User Details: Allow users to enter their name, date of birth, and gender using input fields and pickers.
  2. Store User Data: Save user information securely in Firestore database using the unique user ID as the document identifier.
  3. Navigate to Dashboard: Upon successful detail saving, navigate the user to the main chat screen.

Building the Dashboard Screen:

  1. Fetch User Data: Retrieve a list of users from Firestore and display them in a user list.
  2. Fetch Current User Info: Get the current user’s name from Firestore.
  3. Navigate to Chat: Allow users to tap on other users to initiate a chat conversation.
  4. Logout Functionality: Enable users to securely log out and return to the Login screen.

Building the Chat Screen:

  1. Real-time Messaging: Implement chat functionality using the GiftedChat library for a robust and customizable chat UI.
  2. Firestore Integration: Store and retrieve chat messages in real-time using Firestore database.
  3. Send and Receive Messages: Handle user input, format timestamps, and update the chat UI with new messages.
  4. Customize Chat UI: Tailor the chat bubble appearance and layout to your liking.

Building the AppNavigator:

  1. Manage User Authentication: Check the user’s authentication state and display the appropriate screen (Login or Dashboard).
  2. Navigation Stack: Configure the navigation flow between different screens using React Navigation’s Stack.Navigator.
  3. Smooth Transitions: Ensure seamless transitions between screens based on user actions and authentication status.

Wrapping Up:

  1. Import AppNavigator: Connect the AppNavigator component to your main App.js file to integrate all screens and navigation logic.
  2. Testing and Refinement: Run the app, test its functionality, and address any issues that arise.
  3. Customization and Extension: Personalize the app’s appearance and features based on your preferences and requirements.

Check out the full video of the chat app:

Source code link: