Build a Complete Secure Chat APP using Firebase and React Native & Expo
Signal Clone
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:
- Initialize Expo Project: Choose a template and name your app (e.g., “chatapp”). Install necessary dependencies and set up React Navigation for smooth transitions.
- 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.
- 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:
- Import Modules: Include React, React Native, Firebase, and React Navigation for state management, authentication, and navigation.
- State Variables: Define variables for phone number, verification code, and confirmation object.
- Phone Number Verification: Handle input validation and send verification code using Firebase’s signInWithPhoneNumber method.
- 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)
- User Interface: Design a user-friendly interface with input fields, buttons, and error messages.
Building the Detail Screen:
- Capture User Details: Allow users to enter their name, date of birth, and gender using input fields and pickers.
- Store User Data: Save user information securely in Firestore database using the unique user ID as the document identifier.
- Navigate to Dashboard: Upon successful detail saving, navigate the user to the main chat screen.
Building the Dashboard Screen:
- Fetch User Data: Retrieve a list of users from Firestore and display them in a user list.
- Fetch Current User Info: Get the current user’s name from Firestore.
- Navigate to Chat: Allow users to tap on other users to initiate a chat conversation.
- Logout Functionality: Enable users to securely log out and return to the Login screen.
Building the Chat Screen:
- Real-time Messaging: Implement chat functionality using the GiftedChat library for a robust and customizable chat UI.
- Firestore Integration: Store and retrieve chat messages in real-time using Firestore database.
- Send and Receive Messages: Handle user input, format timestamps, and update the chat UI with new messages.
- Customize Chat UI: Tailor the chat bubble appearance and layout to your liking.
Building the AppNavigator:
- Manage User Authentication: Check the user’s authentication state and display the appropriate screen (Login or Dashboard).
- Navigation Stack: Configure the navigation flow between different screens using React Navigation’s Stack.Navigator.
- Smooth Transitions: Ensure seamless transitions between screens based on user actions and authentication status.
Wrapping Up:
- Import AppNavigator: Connect the AppNavigator component to your main App.js file to integrate all screens and navigation logic.
- Testing and Refinement: Run the app, test its functionality, and address any issues that arise.
- 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: