<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Balogh Botond</title>
    <description>The latest articles on DEV Community by Balogh Botond (@balogh08).</description>
    <link>https://dev.to/balogh08</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1104123%2F18231306-f6b2-4040-b5be-c87af0e3200f.jpeg</url>
      <title>DEV Community: Balogh Botond</title>
      <link>https://dev.to/balogh08</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/balogh08"/>
    <language>en</language>
    <item>
      <title>Facebook Authentication with Firebase in React Native (Android)</title>
      <dc:creator>Balogh Botond</dc:creator>
      <pubDate>Wed, 17 Jan 2024 12:36:45 +0000</pubDate>
      <link>https://dev.to/balogh08/facebook-authentication-with-firebase-in-react-native-android-f1c</link>
      <guid>https://dev.to/balogh08/facebook-authentication-with-firebase-in-react-native-android-f1c</guid>
      <description>&lt;p&gt;This guide provides a comprehensive walkthrough for integrating Facebook Login with Firebase in an Android React Native application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Prerequisites&lt;/li&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;Installing the Facebook SDK&lt;/li&gt;
&lt;li&gt;Configuring Firebase&lt;/li&gt;
&lt;li&gt;Configuring Facebook&lt;/li&gt;
&lt;li&gt;Facebook SDK Configuration&lt;/li&gt;
&lt;li&gt;Coding the Authentication Process&lt;/li&gt;
&lt;li&gt;Logging Out&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;To follow this guide, you should have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Basic knowledge of React and React Native&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Balogh08/CodePlayground/tree/facebook_native_auth_android" rel="noopener noreferrer"&gt;A React Native environment set up&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Firebase project and Facebook Developer account&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Facebook Login integration provides a convenient and secure way for users to log into your app. It not only streamlines the user experience but also leverages the robust security infrastructure of Facebook. This guide will help you set it up step-by-step.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing the Facebook SDK
&lt;/h2&gt;

&lt;p&gt;To integrate Facebook authentication in your React Native application, the first step is to install the Facebook SDK. This SDK provides the necessary tools and functions to facilitate Facebook Login in your app. To install the SDK, run the following command in your project's root directory:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

npm install react-native-fbsdk-next


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;It is a React Native wrapper around the Facebook SDK. It simplifies integrating Facebook services into your application. After installation, you can use the various functionalities provided by the SDK, including &lt;code&gt;Facebook Login&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For more details about this package &lt;a href="https://www.npmjs.com/package/react-native-fbsdk-next" rel="noopener noreferrer"&gt;check the npm site.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Configuring Firebase
&lt;/h2&gt;

&lt;p&gt;To enable Facebook authentication in your React Native application, you need to configure your Firebase project to support Facebook login. Follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Go to the Firebase Console&lt;/strong&gt;: Navigate to the &lt;a href="https://console.firebase.google.com/" rel="noopener noreferrer"&gt;Firebase Console&lt;/a&gt; and select your project.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Access Authentication Settings&lt;/strong&gt;: From the Firebase project dashboard, go to &lt;code&gt;Authentication&lt;/code&gt; &amp;gt; &lt;code&gt;Sign-in method&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Add New Provider&lt;/strong&gt;: Click on &lt;code&gt;Add new provider&lt;/code&gt; and select &lt;code&gt;Facebook&lt;/code&gt; from the list of available providers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Enable Facebook Authentication&lt;/strong&gt;: Enable Facebook as a sign-in provider and input the &lt;code&gt;App ID&lt;/code&gt; and &lt;code&gt;App Secret&lt;/code&gt;.

&lt;ul&gt;
&lt;li&gt;The App ID and App Secret are obtained from your Facebook Developer account, associated with the Facebook app you've set up for authentication. See the next step!&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Configuring Facebook
&lt;/h2&gt;

&lt;p&gt;For integrating Facebook Login, you need to set up an app in your Facebook Developer account. Follow these guidelines:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Create a Facebook Developer Account&lt;/strong&gt;: If you don't have one already, create a Facebook Developer account at &lt;a href="https://developers.facebook.com/" rel="noopener noreferrer"&gt;Facebook Developers&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Create a New App&lt;/strong&gt;: Go to &lt;a href="https://developers.facebook.com/apps" rel="noopener noreferrer"&gt;Facebook Apps&lt;/a&gt;, and create a new app. Select the appropriate use case, typically &lt;code&gt;Authenticate and request data from users with Facebook&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Configure Your App&lt;/strong&gt;: Copy and paste the &lt;code&gt;App Id&lt;/code&gt;, and &lt;code&gt;App Secret&lt;/code&gt; to the Firebase console as mentioned in the &lt;code&gt;Configuring Firebase&lt;/code&gt; part and copy and paste the &lt;code&gt;OAuth Redirect URIs&lt;/code&gt; to the Facebook dashboard.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Find the &lt;strong&gt;App ID&lt;/strong&gt; in the top right corner of the dashboard.&lt;/li&gt;
&lt;li&gt;Obtain the &lt;strong&gt;App Secret&lt;/strong&gt; from &lt;code&gt;App Settings &amp;gt; Basic&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Configure &lt;strong&gt;OAuth Redirect URIs&lt;/strong&gt; in the &lt;code&gt;Facebook Login&lt;/code&gt; settings under &lt;code&gt;Use cases &amp;gt; Customize &amp;gt; Settings&lt;/code&gt;.
You can add the necessary &lt;code&gt;permission&lt;/code&gt; at the &lt;code&gt;Use cases &amp;gt; Customize&lt;/code&gt; like &lt;code&gt;email&lt;/code&gt; or &lt;code&gt;user profile&lt;/code&gt;. It depends on the need of your application to know what permissions to request.&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbekdnf55fzn4jqqv139m.jpeg" alt="Permission joke"&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Save the Changes&lt;/strong&gt;: save changes on both platforms, Facebook and Firebase.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Facebook SDK Configuration
&lt;/h2&gt;

&lt;p&gt;This section of the guide will walk you through the necessary steps to update your &lt;a href="https://developers.facebook.com/docs/facebook-login/android/" rel="noopener noreferrer"&gt;Facebook SDK Configuration&lt;/a&gt; effectively.&lt;/p&gt;

&lt;p&gt;Steps 1,3,4,5,6 needed to be taken. Step 2 is managed by the &lt;code&gt;react-native-fbsdk-next&lt;/code&gt; node package and the rest is not related to this. Step 7 allows the user to log into the app by pressing a push notification which is not relevant now.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Select an app or create a new app&lt;/strong&gt;&lt;br&gt;
By now you should have the app in the Facebook dashboard, so just select the one in which you want to implement Facebook authentication.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Integrate the Facebook SDK&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Updating &lt;code&gt;build.gradle&lt;/code&gt; (Project Level)&lt;br&gt;
It's essential to make sure your project's &lt;code&gt;build.gradle&lt;/code&gt; file includes &lt;code&gt;mavenCentral()&lt;/code&gt; in the repositories section. This is usually included by default, but it's always good to check.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gradle"&gt;&lt;code&gt;

&lt;span class="k"&gt;buildscript&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;repositories&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// other repositories&lt;/span&gt;
        &lt;span class="n"&gt;mavenCentral&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// Ensure this is included&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="c1"&gt;// rest of the buildscript&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Updating &lt;code&gt;build.gradle&lt;/code&gt; (Module: app)&lt;br&gt;
Next, you need to add the Facebook login dependency to your app module's &lt;code&gt;build.gradle&lt;/code&gt; file.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gradle"&gt;&lt;code&gt;

&lt;span class="k"&gt;dependencies&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// other dependencies&lt;/span&gt;
    &lt;span class="n"&gt;implementation&lt;/span&gt; &lt;span class="s1"&gt;'com.facebook.android:facebook-login:latest.release'&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Edit Your Resources and Manifest&lt;/strong&gt;&lt;br&gt;
Update your &lt;code&gt;strings.xml&lt;/code&gt; file with the necessary Facebook credentials. These are crucial for the SDK to function correctly. If facebookAppId is &lt;code&gt;12345&lt;/code&gt; then the fbLoginProtocolScheme is &lt;code&gt;fb12345&lt;/code&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;

&lt;span class="nt"&gt;&amp;lt;string&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"facebook_app_id"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;yourFacebookAppId&lt;span class="nt"&gt;&amp;lt;/string&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;string&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"fb_login_protocol_scheme"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;fbYourFacebookAppId&lt;span class="nt"&gt;&amp;lt;/string&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;string&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"facebook_client_token"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;yourFacebookClientToken&lt;span class="nt"&gt;&amp;lt;/string&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;AndroidManifest.xml&lt;/code&gt; requires internet permission and specific meta-data about ApplicationId and ClientToken for Facebook integration. Finally, add the specific &lt;code&gt;activities&lt;/code&gt; as provided in the example.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;

&lt;span class="nt"&gt;&amp;lt;uses-permission&lt;/span&gt; &lt;span class="na"&gt;android:name=&lt;/span&gt;&lt;span class="s"&gt;"android.permission.INTERNET"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;application&lt;/span&gt; &lt;span class="na"&gt;android:label=&lt;/span&gt;&lt;span class="s"&gt;"@string/app_name"&lt;/span&gt; &lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!-- other meta-data --&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta-data&lt;/span&gt; &lt;span class="na"&gt;android:name=&lt;/span&gt;&lt;span class="s"&gt;"com.facebook.sdk.ApplicationId"&lt;/span&gt; &lt;span class="na"&gt;android:value=&lt;/span&gt;&lt;span class="s"&gt;"@string/facebook_app_id"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta-data&lt;/span&gt; &lt;span class="na"&gt;android:name=&lt;/span&gt;&lt;span class="s"&gt;"com.facebook.sdk.ClientToken"&lt;/span&gt; &lt;span class="na"&gt;android:value=&lt;/span&gt;&lt;span class="s"&gt;"@string/facebook_client_token"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!-- other activities --&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;activity&lt;/span&gt; &lt;span class="na"&gt;android:name=&lt;/span&gt;&lt;span class="s"&gt;"com.facebook.FacebookActivity"&lt;/span&gt;
        &lt;span class="na"&gt;android:configChanges=&lt;/span&gt;&lt;span class="s"&gt;"keyboard|keyboardHidden|screenLayout|screenSize|orientation"&lt;/span&gt;
        &lt;span class="na"&gt;android:label=&lt;/span&gt;&lt;span class="s"&gt;"@string/app_name"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;activity&lt;/span&gt;
        &lt;span class="na"&gt;android:name=&lt;/span&gt;&lt;span class="s"&gt;"com.facebook.CustomTabActivity"&lt;/span&gt;
        &lt;span class="na"&gt;android:exported=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;intent-filter&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;action&lt;/span&gt; &lt;span class="na"&gt;android:name=&lt;/span&gt;&lt;span class="s"&gt;"android.intent.action.VIEW"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;category&lt;/span&gt; &lt;span class="na"&gt;android:name=&lt;/span&gt;&lt;span class="s"&gt;"android.intent.category.DEFAULT"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;category&lt;/span&gt; &lt;span class="na"&gt;android:name=&lt;/span&gt;&lt;span class="s"&gt;"android.intent.category.BROWSABLE"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;data&lt;/span&gt; &lt;span class="na"&gt;android:scheme=&lt;/span&gt;&lt;span class="s"&gt;"@string/fb_login_protocol_scheme"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/intent-filter&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/activity&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/application&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 5: Associate Your Package Name and Default Class with Your App&lt;/strong&gt;&lt;br&gt;
React Native doesn't include the package name in the default &lt;code&gt;AndroidManifest.xml&lt;/code&gt;. However, you can find it in the &lt;code&gt;build.gradle(app)&lt;/code&gt; file as &lt;code&gt;applicationId "com.codeplayground"&lt;/code&gt;. For the Default Activity Class Name, use &lt;code&gt;thepackagename.MainActivity&lt;/code&gt;. You'll find the &lt;code&gt;MainActivity&lt;/code&gt; file at &lt;code&gt;android/app/src/main/java/com/yourAppName/MainActivity.kt&lt;/code&gt;, but no further action is required with this file for now.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6: Provide Development and Release Key Hashes for Your App&lt;/strong&gt;&lt;br&gt;
Generating key hashes for your app. Follow the detailed instructions provided in the &lt;a href="https://developers.facebook.com/docs/facebook-login/android/#:~:text=Save-,6.%20Provide%20the%20Development%20and%20Release%20Key%20Hashes%20for%20Your%20App,-To%20ensure%20the" rel="noopener noreferrer"&gt;Facebook documentation&lt;/a&gt;. Once you have created the hashes, paste them into the &lt;code&gt;Key Hashes&lt;/code&gt; field in your Facebook Developer account and save the changes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Coding the Authentication Process
&lt;/h2&gt;

&lt;p&gt;To set up the authentication process, follow these steps:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Install React Native Firebase SDK:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

   npm &lt;span class="nb"&gt;install&lt;/span&gt; @react-native-firebase/app
   npm &lt;span class="nb"&gt;install&lt;/span&gt; @react-native-firebase/auth


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Create &lt;code&gt;firebase.js&lt;/code&gt;:&lt;/strong&gt;&lt;br&gt;
   In your project root, create a file named &lt;code&gt;firebase.js&lt;/code&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

   &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;firebase&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@react-native-firebase/app&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

   &lt;span class="c1"&gt;// Basic Firebase configuration&lt;/span&gt;
   &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;firebaseConfig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="na"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;API_KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
     &lt;span class="na"&gt;authDomain&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;AUTH_DOMAIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
     &lt;span class="na"&gt;projectId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PROJECT_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
     &lt;span class="na"&gt;storageBucket&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;STORAGE_BUCKET&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
     &lt;span class="na"&gt;messagingSenderId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;MESSAGING_SENDER_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
     &lt;span class="na"&gt;appId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;APP_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
     &lt;span class="na"&gt;measurementId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;MEASUREMENT_ID&lt;/span&gt;
   &lt;span class="p"&gt;};&lt;/span&gt;

   &lt;span class="c1"&gt;// Initialize Firebase&lt;/span&gt;
   &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;firebase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;apps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;firebase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;initializeApp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firebaseConfig&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Configure Build Settings:&lt;/strong&gt;&lt;br&gt;
   In &lt;code&gt;build.gradle (app)&lt;/code&gt;, add:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gradle"&gt;&lt;code&gt;

   &lt;span class="n"&gt;apply&lt;/span&gt; &lt;span class="nl"&gt;from:&lt;/span&gt; &lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;':react-native-config'&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;projectDir&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getPath&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;"/dotenv.gradle"&lt;/span&gt;

   &lt;span class="n"&gt;defaultConfig&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
       &lt;span class="c1"&gt;// ...&lt;/span&gt;
       &lt;span class="n"&gt;resValue&lt;/span&gt; &lt;span class="s2"&gt;"string"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"facebook_app_id"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"FACEBOOK_APP_ID"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
       &lt;span class="n"&gt;resValue&lt;/span&gt; &lt;span class="s2"&gt;"string"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"fb_login_protocol_scheme"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"FB_LOGIN_PROTOCOL_SCHEME"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
       &lt;span class="n"&gt;resValue&lt;/span&gt; &lt;span class="s2"&gt;"string"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"facebook_client_token"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"FACEBOOK_CLIENT_TOKEN"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
   &lt;span class="o"&gt;}&lt;/span&gt;

   &lt;span class="k"&gt;dependencies&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
       &lt;span class="c1"&gt;// ...&lt;/span&gt;
       &lt;span class="n"&gt;implementation&lt;/span&gt; &lt;span class="s1"&gt;'com.facebook.android:facebook-login:latest.release'&lt;/span&gt;
   &lt;span class="o"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Register App with Firebase:&lt;/strong&gt;&lt;br&gt;
   Follow the steps to register your app with Firebase:&lt;br&gt;
   &lt;a href="https://firebase.google.com/docs/android/setup#register-app" rel="noopener noreferrer"&gt;Firebase App Registration Guide&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create Facebook Login Button:&lt;/strong&gt;&lt;br&gt;
   Create a custom component &lt;code&gt;FacebookLoginButton&lt;/code&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

   &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;LoginButton&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;AccessToken&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-native-fbsdk-next&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;auth&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@react-native-firebase/auth&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useNavigation&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@react-navigation/native&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;FacebookLoginButton&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;navigation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useNavigation&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleFacebookLogin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Once signed in, get the user AccessToken&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;AccessToken&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getCurrentAccessToken&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Something went wrong obtaining access token&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="c1"&gt;// Create a Firebase credential with the AccessToken&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;facebookCredential&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;FacebookAuthProvider&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;credential&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;accessToken&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userCredential&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;signInWithCredential&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;facebookCredential&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;User signed in with Facebook!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;userCredential&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;navigation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;navigate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Home&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Facebook login or Firebase credential failed:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;LoginButton&lt;/span&gt;
      &lt;span class="nx"&gt;onLoginFinished&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleFacebookLogin&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="nx"&gt;onLogoutFinished&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;logout.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;FacebookLoginButton&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Add FacebookLoginButton to the Login page.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import FacebookLoginButton from '../components/FacebookLoginButton';

...
  return (
    &amp;lt;View&amp;gt;
      ...
      &amp;lt;FacebookLoginButton /&amp;gt;
    &amp;lt;/View&amp;gt;
  );


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Start your application on your device or simulator and try it out. Pressing the Facebook button should navigate to Facebook authentication and back after successful authentication. It is up to you how to handle the successful login. In my case, the app navigates to the &lt;code&gt;Home.js&lt;/code&gt;, but to improve a &lt;code&gt;useLayoutEffect&lt;/code&gt; could be used for more smooth animation.&lt;br&gt;
   Source: &lt;a href="https://rnfirebase.io/auth/social-auth" rel="noopener noreferrer"&gt;Firebase Authentication with Social Providers&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Logging Out
&lt;/h2&gt;

&lt;p&gt;After logging in you want the user to be able to log out as well. Besides logging out the user by the Firebase &lt;code&gt;signOut&lt;/code&gt; function, also Facebook logout must be implemented by the &lt;code&gt;LoginManager&lt;/code&gt;::&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;auth&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@react-native-firebase/auth&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;LoginManager&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-native-fbsdk-next&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleLogout&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;signOut&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Log out from Facebook&lt;/span&gt;
    &lt;span class="nx"&gt;LoginManager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;logOut&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;Alert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Logout Failed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Login page&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F85ry6bo29mhizvs5l158.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F85ry6bo29mhizvs5l158.png" alt="Log in by Facebook"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Facebook authentication in Hungarian&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5co1gjp072h96vjk4ynd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5co1gjp072h96vjk4ynd.png" alt="FB authentication in Hungarian"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The user is logged in by Facebook.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff56pu8czya2uc8yvsu3g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff56pu8czya2uc8yvsu3g.png" alt="Logged in by Facebook"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;By following these steps, users can seamlessly log in and log out using Facebook in your React Native Android application. In the Facebook developer dashboard, you can customize what information to ask for from the user while logging in with Facebook.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check out the final code&lt;/strong&gt; &lt;a href="https://github.com/Balogh08/CodePlayground/tree/facebook_native_auth_android" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;br&gt;
The &lt;code&gt;IOS&lt;/code&gt; version is coming soon. Let me know your thoughts on this article. Which third party do you prefer for authentication?&lt;/p&gt;

&lt;p&gt;Thank you for reading.&lt;br&gt;
More about the author at &lt;a href="//www.lunitech.hu"&gt;LUNitECH&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;The article was written with the help of existing documentation, ChatGPT, Grammarly, and other human beings.&lt;/small&gt;&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>firebase</category>
      <category>android</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Cleaning Your Git History: Safely Removing Sensitive Data</title>
      <dc:creator>Balogh Botond</dc:creator>
      <pubDate>Tue, 19 Dec 2023 19:23:01 +0000</pubDate>
      <link>https://dev.to/balogh08/cleaning-your-git-history-safely-removing-sensitive-data-10i5</link>
      <guid>https://dev.to/balogh08/cleaning-your-git-history-safely-removing-sensitive-data-10i5</guid>
      <description>&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;Understanding git filter-branch&lt;/li&gt;
&lt;li&gt;Step-by-Step Guide&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;While working on integrating third-party API into my project, I made a critical mistake in software development. I accidentally committed my &lt;code&gt;API keys&lt;/code&gt; directly in a configuration file, rather than using a &lt;code&gt;.env&lt;/code&gt; file that is part of the &lt;code&gt;.gitignore&lt;/code&gt;. My repository was still &lt;code&gt;private&lt;/code&gt;, but with plans to go public, I needed to remove this information from the git history.&lt;/p&gt;

&lt;p&gt;How to remove the commits containing the sensitive information from my history? After some research, I decided to use the &lt;code&gt;git filter-branch&lt;/code&gt; command. In the end, it worked as it was expected. I did not lose anything else from my git history only the commits related to the certain config file and the config file itself which I had to recreate with the help of a backup branch.&lt;/p&gt;

&lt;p&gt;Whether you're a seasoned developer or new to the realm of version control, this guide will provide a clear, step-by-step approach to ensure to remove safely commits from a branch that are related to a specific file.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Git filter-branch
&lt;/h2&gt;

&lt;p&gt;About &lt;code&gt;git filter-branch&lt;/code&gt;, it is a powerful and yet dangerous tool of git. It allows you to modify your commit history in various ways, such as changing commit messages, author details, or, as in my case, removing commits that contain sensitive information like API keys. It works by filtering the entire branch history, committing anew based on the changes you specify. &lt;/p&gt;

&lt;p&gt;Please use it with caution. It can lead to data loss or discrepancies in your project's history. It's recommended to use this tool in a controlled environment (like a private repository) and ensure you have complete backups of your data before proceeding. Furthermore, if you're working in a team, coordinating with your colleagues is essential to avoid conflicts or data inconsistencies once the history is altered. Check the documentation and especially safety information before using it. &lt;a href="https://git-scm.com/docs/git-filter-branch" rel="noopener noreferrer"&gt;Git filter-branch documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwdxi343wc9g50fag54k3.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwdxi343wc9g50fag54k3.jpeg" alt="Dombledore meme"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step-by-Step Guide
&lt;/h2&gt;

&lt;p&gt;The branch I was working on was named &lt;code&gt;secret_keys&lt;/code&gt; in which I committed and pushed the &lt;code&gt;secret_key&lt;/code&gt; in the &lt;code&gt;config.js&lt;/code&gt; file. That’s where the trouble begins… I did not realise it for a while so many other commits had been pushed to the repo.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzwaxhvrzwjs8kystpzb0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzwaxhvrzwjs8kystpzb0.png" alt="Commits to remove"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First, I added the &lt;code&gt;.env&lt;/code&gt; to my &lt;code&gt;.gitignore&lt;/code&gt; and pushed it to the repo. After that, I created the &lt;code&gt;.env&lt;/code&gt; file which is not part of the version history, and added the secret key to that file from my &lt;code&gt;config.js&lt;/code&gt; I referred to the &lt;code&gt;.env&lt;/code&gt; file instead of hardcoding the secret key in the &lt;code&gt;config.js&lt;/code&gt; file itself.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3ympjz9iuu1ptl86rik7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3ympjz9iuu1ptl86rik7.png" alt=".env secret key"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this situation, the secret key is available in the version control. I must get rid of this. Here comes the git filter-branch command. But first, let me create a backup branch for safety: &lt;code&gt;secret_key_backup&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Then I opened a terminal in my project, and made sure that I was on the desired branch:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

git checkout secret_keys


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

Switched to branch 'secret_keys'
Your branch is up to date with 'origin/secret_keys'.


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here you can see the main commits that must be removed for safety&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbhswiplq1378knobga3q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbhswiplq1378knobga3q.png" alt="Main commits to be removed"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, I ran the git filter-branch command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

git filter-branch &lt;span class="nt"&gt;--force&lt;/span&gt; &lt;span class="nt"&gt;--index-filter&lt;/span&gt; &lt;span class="s2"&gt;"git rm --cached --ignore-unmatch file_containing_secret_keys.js"&lt;/span&gt; &lt;span class="nt"&gt;--prune-empty&lt;/span&gt; &lt;span class="nt"&gt;--tag-name-filter&lt;/span&gt; &lt;span class="nb"&gt;cat&lt;/span&gt; &lt;span class="nt"&gt;--&lt;/span&gt; branch_name_containing_commits_to_remove


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;git filter-branch&lt;/code&gt;: Initiates the process of rewriting the git history.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--force&lt;/code&gt;: Forces the rewrite of history, necessary if you've already run filter-branch before. Overrides the safety checks to prevent overwriting existing backups.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--index-filter&lt;/code&gt;: Specifies a filter to rewrite the index at each revision.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;"git rm --cached --ignore-unmatch file_containing_secret_keys.js"&lt;/code&gt;: The command that &lt;code&gt;--index-filter&lt;/code&gt; runs for each commit.

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;git rm --cached&lt;/code&gt;: Removes the specified file from the index (staging area) but not from the working directory.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--ignore-unmatch&lt;/code&gt;: Prevents errors if the file isn't found in a particular commit.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;file_containing_secret_keys.js&lt;/code&gt;: The specific file you want to remove from your history.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;
&lt;code&gt;--prune-empty&lt;/code&gt;: Tells git filter-branch to remove commits that become empty after the filter has been applied.&lt;/li&gt;

&lt;li&gt;
&lt;code&gt;--tag-name-filter cat&lt;/code&gt;: This filter is applied to tag names that point to rewritten commits. &lt;code&gt;cat&lt;/code&gt; just keeps the original tag name.&lt;/li&gt;

&lt;li&gt;
&lt;code&gt;--&lt;/code&gt;: Separator that clarifies the end of the options and the beginning of the branch specification.&lt;/li&gt;

&lt;li&gt;
&lt;code&gt;branch_name_containing_commits_to_remove&lt;/code&gt;: Specifies the branch whose history you want to rewrite.&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;This command is tailored to remove a specific file from the history of a given branch, eliminating all references to that file in your commits.&lt;/p&gt;

&lt;p&gt;In my case:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

git filter-branch &lt;span class="nt"&gt;--force&lt;/span&gt; &lt;span class="nt"&gt;--index-filter&lt;/span&gt; &lt;span class="s2"&gt;"git rm --cached --ignore-unmatch config.js"&lt;/span&gt; &lt;span class="nt"&gt;--prune-empty&lt;/span&gt; &lt;span class="nt"&gt;--tag-name-filter&lt;/span&gt; &lt;span class="nb"&gt;cat&lt;/span&gt; &lt;span class="nt"&gt;--&lt;/span&gt; secret_keys


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

**WARNING**: git-filter-branch has a glut of gotchas generating mangled history rewrites. Hit Ctrl-C before proceeding to abort, then use an alternative filtering tool such as 'git filter-repo' (https://github.com/newren/git-filter-repo/) instead. See the filter-branch manual page for more details; to squelch this warning, set FILTER_BRANCH_SQUELCH_WARNING=1.

Proceeding with filter-branch...

Rewrite a3a48b09e282854c80bf4ad02a017e249e161fd8 (2/8) (0 seconds passed, remaining 0 predicted)    rm 'config.js'
Rewrite 6e788e83a338e45b348d93d682b32c816ee2fbff (3/8) (0 seconds passed, remaining 0 predicted)    rm 'config.js'
Rewrite 7a378a0145bce70bea213ca5f9062138544db5f2 (4/8) (0 seconds passed, remaining 0 predicted)    rm 'config.js'
Rewrite 0637c9659623644cfceb35be10f2a1fe5c468e04 (5/8) (0 seconds passed, remaining 0 predicted)    rm 'config.js'
Rewrite 6c421eb99adc6b987cff7f3cada31e9313638072 (6/8) (0 seconds passed, remaining 0 predicted)    rm 'config.js'
Rewrite 98001e5b97270efa4a8ab5bd0452be56dd76883d (7/8) (0 seconds passed, remaining 0 predicted)    rm 'config.js'
Rewrite 2ca4e161a4af2b8f38c46faf848fdbb3e550f23c (8/8) (0 seconds passed, remaining 0 predicted)    rm 'config.js'

Ref 'refs/heads/secret_keys' was rewritten.


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjn0aoyekmnlb2niagg7z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjn0aoyekmnlb2niagg7z.png" alt="Commits removed"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the image, you can see 2 commits left, as the placeholder commits I made were related to the &lt;code&gt;config.js&lt;/code&gt; so they were removed as well. If I pull the repo then I would get back to the previous state so the deleted commits can be retrieved from the repo at this point. It will create a merge commit which you could push back and then all your commits would be restored, but we want them to be deleted so do not do that unless you want to play around a bit.&lt;/p&gt;

&lt;p&gt;To apply the modification, you need to force push:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

git push origin branch_name_containing_commits_to_remove &lt;span class="nt"&gt;--force&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Proceed with caution!&lt;br&gt;
Once you force push this modification,  there is &lt;strong&gt;NO RETURN&lt;/strong&gt;!&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8i7s73spe5bzb8h6fp23.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8i7s73spe5bzb8h6fp23.jpeg" alt="No return from force push"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In my case:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

git push origin secret_keys &lt;span class="nt"&gt;--force&lt;/span&gt;                        


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 293 bytes | 293.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/Balogh08/GitFilterBranch.git
 + 2ca4e16...e61bbd2 secret_keys -&amp;gt; secret_keys (forced update)


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And abracadabra, the commits and the file which once contained the sensitive information are now removed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftj6076pqehzjkx7s3n42.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftj6076pqehzjkx7s3n42.png" alt="Commits removed and pushed"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we need to replace the file without the sensitive information. For this, we can use the backup branch to copy the content of &lt;code&gt;config.js&lt;/code&gt; and create a new &lt;code&gt;config.js&lt;/code&gt; in the branch without the sensitive commits. Then, paste the content from the backup branch. If you did not publish the backup branch, then you can easily delete it. However, if you published it, you must go through the same process with &lt;code&gt;git filter-branch&lt;/code&gt; on the backup branch, but without creating a second backup for the backup. Simply deleting the branch from the remote repository is not safe enough, as the keys to the commits containing sensitive information would remain somewhere in the source control system.&lt;/p&gt;

&lt;p&gt;What are your thoughts on this solution? What alternatives do you prefer, like &lt;code&gt;git filter-repo&lt;/code&gt;? Let me know in the comments.&lt;/p&gt;

&lt;p&gt;More about the author at &lt;a href="//www.lunitech.hu"&gt;LUNitECH&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;The article was written with the help of existing documentation, ChatGPT, Grammarly, and other human beings.&lt;/small&gt;&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>learning</category>
      <category>git</category>
    </item>
    <item>
      <title>Email Authentication with Firebase in React Native for iOS and Android</title>
      <dc:creator>Balogh Botond</dc:creator>
      <pubDate>Wed, 13 Dec 2023 16:13:23 +0000</pubDate>
      <link>https://dev.to/balogh08/email-authentication-with-firebase-in-react-native-for-ios-and-android-4l74</link>
      <guid>https://dev.to/balogh08/email-authentication-with-firebase-in-react-native-for-ios-and-android-4l74</guid>
      <description>&lt;p&gt;This post aims to provide a comprehensive guide on implementing email authentication in a React Native application using Firebase. As of December 2023, I leverage some of the latest packages and methodologies to build a secure and efficient authentication system. My main goal is to practice writing clear and effective instructional guides, which others and I can use later. The article was written with the help of existing documentation, AI tools like ChatGPT and Grammarly - I’m not sure if it uses AI yet, probably yes - and other human beings.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of content
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Prerequisites&lt;/li&gt;
&lt;li&gt;Development Stack&lt;/li&gt;
&lt;li&gt;Setting Up the React Native Environment&lt;/li&gt;
&lt;li&gt;Setting Up Firebase for Email Authentication&lt;/li&gt;
&lt;li&gt;Structuring the React Native Project&lt;/li&gt;
&lt;li&gt;Signup&lt;/li&gt;
&lt;li&gt;Logout&lt;/li&gt;
&lt;li&gt;Login&lt;/li&gt;
&lt;li&gt;Conditional Navigation Based on Authentication State&lt;/li&gt;
&lt;li&gt;Additional Features and Improvements&lt;/li&gt;
&lt;li&gt;Sources&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;p&gt;To get the most out of this tutorial, you should have a fundamental understanding of React and React Native, familiarity with npm for package management, and experience with Git for version control. The guide assumes a working knowledge of these technologies, allowing us to focus on the specific task of integrating Firebase for authentication purposes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Development Stack
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;npm: 10.1.&lt;/li&gt;
&lt;li&gt;Node.js: v20.9.0&lt;/li&gt;
&lt;li&gt;Watchman: 2023.10.30.00&lt;/li&gt;
&lt;li&gt;Visual Studio Code (VSCode): 1.85.0&lt;/li&gt;
&lt;li&gt;Xcode: 14.2&lt;/li&gt;
&lt;li&gt;Android Studio: Android Studio Giraffe | 2022.3.1 &lt;/li&gt;
&lt;li&gt;Java: Version 17&lt;/li&gt;
&lt;li&gt;React Native: 0.73.0&lt;/li&gt;
&lt;li&gt;React Native CLI: removed as the official react-native doc suggests it&lt;/li&gt;
&lt;li&gt;Firebase: 10.7.1&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Setting Up the React Native Environment
&lt;/h3&gt;

&lt;p&gt;You can follow the instructions specific to your development OS and target OS: &lt;a href="https://reactnative.dev/docs/environment-setup?guide=native&amp;amp;platform=ios" rel="noopener noreferrer"&gt;RN documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Make sure you carefully follow the guide for both &lt;code&gt;iOS&lt;/code&gt; and &lt;code&gt;Android&lt;/code&gt;. Make sure you have installed the correct version of npm, node, Xcode, android studio, android SDKs, java, etc.&lt;/p&gt;

&lt;h4&gt;
  
  
  Initializing the React Native Project
&lt;/h4&gt;

&lt;p&gt;To create a new project, run:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npx react-native@latest init CodePlayground&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After successful initialization, you should see a series of steps being completed, including template downloading, dependency installation, and potentially CocoaPods setup for iOS.&lt;/p&gt;

&lt;h4&gt;
  
  
  Testing the Setup
&lt;/h4&gt;

&lt;p&gt;It's a good practice to test the setup on both iOS and Android platforms. Navigate to your project directory:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cd CodePlayground&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Run the default app on both simulators to confirm everything is set up correctly:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm start&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then, press &lt;code&gt;i&lt;/code&gt; to run on iOS and &lt;code&gt;a&lt;/code&gt; to run on Android.&lt;br&gt;
Note that sometimes an initial build might fail, particularly if specific SDKs or configurations are missing. In such cases, open Xcode for iOS and Android Studio for Android to build the app once and ensure all necessary components are installed.&lt;br&gt;
After making sure everything works properly so far, use your favorite version control like git to keep track of changes. &lt;em&gt;(Optional)&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Setting Up Firebase for Email Authentication
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Start a New Project&lt;/strong&gt;: Navigate to the &lt;a href="https://console.firebase.google.com/" rel="noopener noreferrer"&gt;Firebase Console&lt;/a&gt; and start a new project. Enter a project name and accept the default settings.
&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqyh5xfsrlfr8s7omhjyu.png" alt="New project" width="800" height="268"&gt;
&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsbikgr9671sahx38cwyj.png" alt="Add name" width="791" height="596"&gt;
&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F032isfhga73mibgffk0l.png" alt="Default settings" width="800" height="821"&gt;
&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl3ywgdtaxckgjlhn2hj5.png" alt="Account selection" width="784" height="616"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Project Creation&lt;/strong&gt;: While Firebase prepares your project, take a brief coffee break! Your new Firebase environment will be ready shortly.
&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgm1w9o59no92n4kj2m0m.png" alt="Project creation" width="244" height="234"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Enable Email/Password Sign-In Method&lt;/strong&gt;: In your Firebase project, go to the Authentication section and enable the 'Email/Password' sign-in provider. This step is crucial for email-based user authentication.
&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkxy35gxyw60t9iao39kz.png" alt="Email authentication select" width="415" height="679"&gt;
&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fshca3xof663itchc4f9f.png" alt="Email auth get started" width="800" height="340"&gt;
&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3z5u9icyjn30okzn103h.png" alt="Select email auth" width="800" height="309"&gt;
&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fidizultbop6l47ck1qmt.png" alt="Enable email auth" width="800" height="360"&gt;
&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6qy4p6vxods90s2u94pn.png" alt="Email auth enabled" width="800" height="241"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Register a Web App&lt;/strong&gt;: To obtain the necessary credentials, add a web application to your Firebase project. Provide a nickname for your app and follow the setup instructions.
&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2xvz96uyyhylheezdkq6.png" alt="Add web app" width="800" height="388"&gt;
&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fftbtyf0lsxihweqomqcc.png" alt="Add name to webapp" width="585" height="501"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Install Firebase in Your Project&lt;/strong&gt;: Run &lt;code&gt;npm install firebase&lt;/code&gt; in your project directory to add Firebase SDK.&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F268r9469g5yh51vvva41.png" alt="Api keys" width="706" height="956"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Initialize Firebase with Configuration&lt;/strong&gt;: Create a &lt;code&gt;firebase.js&lt;/code&gt; file in your project root. Add the following code with your specific configuration
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
import { getAnalytics } from "firebase/analytics";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries

// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
  apiKey: "A….”,
  authDomain: "cod….”,
  projectId: "cod…”,
  storageBucket: "cod…”,
  messagingSenderId: "47…”,
  appId: "1:475…”,
  measurementId: “G…”
}

// Initialize Firebase
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;7.&lt;strong&gt;Use Environment Variables&lt;/strong&gt;: For security, store your Firebase configuration in a &lt;code&gt;.env&lt;/code&gt; file at the root of your project. Add this file to &lt;code&gt;.gitignore&lt;/code&gt; to keep your &lt;code&gt;keys&lt;/code&gt; safe and out of version control.&lt;/p&gt;

&lt;p&gt;Add to your &lt;code&gt;.gitignore&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Environment variables
.env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create &lt;code&gt;.env&lt;/code&gt; in your root&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;API_KEY=A…8
AUTH_DOMAIN=codep…app.com
PROJECT_ID=codep…a
STORAGE_BUCKET=ycode…com
MESSAGING_SENDER_ID=4…2
APP_ID=1:47…f
MEASUREMENT_ID=G…G
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;8.&lt;strong&gt;Install react-native-dotenv&lt;/strong&gt;: Use &lt;code&gt;npm install react-native-dotenv&lt;/code&gt; for safe access to environment variables.&lt;br&gt;
9.&lt;strong&gt;Update Babel Configuration&lt;/strong&gt;: Modify &lt;code&gt;babel.config.js&lt;/code&gt; to include &lt;code&gt;react-native-dotenv&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports = { presets: ['module:@react-native/babel-preset'], plugins: [ ['module:react-native-dotenv', { moduleName: '@env', path: '.env', }], ], };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;10.&lt;strong&gt;Update firabse.js file&lt;/strong&gt;: where you are supposed to copy-paste the configs provided by Firebase and make the following changes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const firebaseConfig = {
  apiKey: process.env.API_KEY,
  authDomain: process.env.AUTH_DOMAIN,
  projectId: process.env.PROJECT_ID,
  storageBucket: process.env.STORAGE_BUCKET,
  messagingSenderId: process.env.MESSAGING_SENDER_ID,
  appId: process.env.APP_ID,
  measurementId: process.env.MEASUREMENT_ID
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, add &lt;code&gt;import { getAuth } from 'firebase/auth';&lt;/code&gt; at the imports of your file and add &lt;code&gt;export const auth = getAuth(app);&lt;/code&gt; to the end of the file&lt;/p&gt;

&lt;p&gt;You can comment out or delete the analytics for now and the &lt;code&gt;firebase.js&lt;/code&gt; in your root should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
// import { getAnalytics } from "firebase/analytics";
import { getAuth } from 'firebase/auth';

// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
  apiKey: process.env.API_KEY,
  authDomain: process.env.AUTH_DOMAIN,
  projectId: process.env.PROJECT_ID,
  storageBucket: process.env.STORAGE_BUCKET,
  messagingSenderId: process.env.MESSAGING_SENDER_ID,
  appId: process.env.APP_ID,
  measurementId: process.env.MEASUREMENT_ID
};

// Initialize Firebase
const app = initializeApp(firebaseConfig);
// const analytics = getAnalytics(app);
export const auth = getAuth(app);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Structuring the React Native Project
&lt;/h2&gt;

&lt;p&gt;Clean up the default react native project and add simple context, src folder, styles, and screens (Login, Signup, and Home)&lt;br&gt;
I added simple stack navigation to the app for screen changing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install @react-navigation/native
npm install react-native-screens react-native-safe-area-context
npm install @react-navigation/native-stack
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import * as React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { SafeAreaProvider, SafeAreaView } from 'react-native-safe-area-context';
import Login from './src/screens/Login';
import Signup from './src/screens/Signup';
import Home from './src/screens/Home';

const Stack = createNativeStackNavigator();

function App() {
  return (
    &amp;lt;SafeAreaProvider&amp;gt;
      &amp;lt;SafeAreaView style={{ flex: 1 }}&amp;gt;
        &amp;lt;NavigationContainer&amp;gt;
          &amp;lt;Stack.Navigator initialRouteName="Login"&amp;gt;
            &amp;lt;Stack.Screen name="Login" component={Login} /&amp;gt;
            &amp;lt;Stack.Screen name="Signup" component={Signup} /&amp;gt;
            &amp;lt;Stack.Screen name="Home" component={Home} /&amp;gt;
          &amp;lt;/Stack.Navigator&amp;gt;
        &amp;lt;/NavigationContainer&amp;gt;
      &amp;lt;/SafeAreaView&amp;gt;
    &amp;lt;/SafeAreaProvider&amp;gt;
  );
}

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { StyleSheet } from 'react-native';

export const GlobalStyles = StyleSheet.create({
  screenContainer: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    margin: 12,
  },
  inputField: {
    height: 40,
    borderColor: 'gray',
    borderWidth: 1,
    width: '100%',
    marginBottom: 15,
    padding: 10,
  },
  button: {
    backgroundColor: 'blue',
    padding: 10,
    borderRadius: 5,
    marginBottom: 15,
  },
  buttonText: {
    color: 'white',
    textAlign: 'center',
  },
  linkText: {
    color: 'blue',
    textAlign: 'center',
    marginTop: 15,
  },
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import { View, Text, TextInput, TouchableOpacity, View } from 'react-native';
import { useNavigation } from '@react-navigation/native';
import { GlobalStyles } from '../styles/GlobalStyles';

export default function Login() {
    const navigation = useNavigation();

    const handleSignUpPress = () =&amp;gt; {
      navigation.navigate('Signup');
    };

    const handleLoginPress = () =&amp;gt; {
      // TODO:Perform authentication...
      navigation.navigate('Home');
    };

    return (
        &amp;lt;View style={GlobalStyles.screenContainer}&amp;gt;
        &amp;lt;TextInput style={GlobalStyles.inputField} placeholder="Email" /&amp;gt;
        &amp;lt;TextInput style={GlobalStyles.inputField} placeholder="Password" secureTextEntry /&amp;gt;
        &amp;lt;TouchableOpacity style={GlobalStyles.button} onPress={handleLoginPress}&amp;gt;
            &amp;lt;Text style={GlobalStyles.buttonText}&amp;gt;Log In&amp;lt;/Text&amp;gt;
        &amp;lt;/TouchableOpacity&amp;gt;
        &amp;lt;Text style={GlobalStyles.linkText} onPress={handleSignUpPress}&amp;gt;Sign Up&amp;lt;/Text&amp;gt;
        &amp;lt;/View&amp;gt;
    );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6d1ik9iczz2b1wt911zr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6d1ik9iczz2b1wt911zr.png" alt="Login" width="750" height="1334"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import { Text, TextInput, TouchableOpacity, View } from 'react-native';
import { useNavigation } from '@react-navigation/native';
import { GlobalStyles } from '../styles/GlobalStyles';

export default function Signup() {  
    const navigation = useNavigation();

    const handleCancelPress = () =&amp;gt; {
      navigation.goBack();
    };

    return (
        &amp;lt;AreaView style={GlobalStyles.screenContainer}&amp;gt;
        &amp;lt;TextInput style={GlobalStyles.inputField} placeholder="Email" /&amp;gt;
        &amp;lt;TextInput style={GlobalStyles.inputField} placeholder="Password" secureTextEntry /&amp;gt;
        &amp;lt;TextInput style={GlobalStyles.inputField} placeholder="Re-enter Password" secureTextEntry /&amp;gt;
        &amp;lt;TouchableOpacity style={GlobalStyles.button}&amp;gt;
            &amp;lt;Text style={GlobalStyles.buttonText}&amp;gt;Sign Up&amp;lt;/Text&amp;gt;
        &amp;lt;/TouchableOpacity&amp;gt;
        &amp;lt;Text style={GlobalStyles.linkText} onPress={handleCancelPress}&amp;gt;Cancel&amp;lt;/Text&amp;gt;
        &amp;lt;/AreaView&amp;gt;
    );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyhvdsvvk5oy3rrvejxr3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyhvdsvvk5oy3rrvejxr3.png" alt="Signup" width="750" height="1334"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import { Text, TouchableOpacity, View } from 'react-native';
import { GlobalStyles } from '../styles/GlobalStyles';

export default function Home() {
  return (
    &amp;lt;View style={GlobalStyles.screenContainer}&amp;gt;
      &amp;lt;Text&amp;gt;Welcome to the Home Screen!&amp;lt;/Text&amp;gt;
      &amp;lt;TouchableOpacity style={GlobalStyles.button}&amp;gt;
        &amp;lt;Text style={GlobalStyles.buttonText}&amp;gt;Sign Out&amp;lt;/Text&amp;gt;
      &amp;lt;/TouchableOpacity&amp;gt;
    &amp;lt;/View&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fven18ngmdjfiufia5ioz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fven18ngmdjfiufia5ioz.png" alt="Home" width="750" height="1334"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Signup
&lt;/h2&gt;

&lt;p&gt;Add signup &lt;code&gt;form validation&lt;/code&gt; and firebase &lt;code&gt;signup&lt;/code&gt; function to &lt;code&gt;Signup.js&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i formik yup&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;New imports:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Formik } from 'formik';
import * as yup from 'yup'; 
import { auth } from '../../firebase';
import { createUserWithEmailAndPassword  } from 'firebase/auth';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Implement &lt;code&gt;signup&lt;/code&gt; in the &lt;code&gt;handleSignup&lt;/code&gt; function and add it to the &lt;code&gt;onSubmit&lt;/code&gt; property of the form.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const handleSignup = async (values, actions) =&amp;gt; {
        if (values.password !== values.confirmPassword) {
            actions.setFieldError('confirmPassword', "Passwords don't match");
            return;
        }
        createUserWithEmailAndPassword(auth, values.email, values.password)
        .then((userCredential) =&amp;gt; {
            console.log('Signed up:', userCredential.user);
            navigation.navigate('Home');
        })
        .catch((error) =&amp;gt; {
            Alert.alert('Signup Failed', error.message);
        });
    };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the full document please check &lt;a href="https://github.com/Balogh08/CodePlayground/blob/email_auth_setup/src/screens/Signup.js" rel="noopener noreferrer"&gt;Signup.js&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Try out, and sign up as a user. Check the Firebase authentication users tab. There is the user!!!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgolcs200ctpgunvj1ek8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgolcs200ctpgunvj1ek8.png" alt="Signed up user" width="800" height="229"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Logout
&lt;/h2&gt;

&lt;p&gt;As the handleSignup function navigates to the Home screen on the happy path, first I implement the logout function, and as there is an authenticated user its email address can be displayed to make sure which user is logged in.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState, useEffect } from 'react';
import { SafeAreaView, Text, TouchableOpacity, Alert } from 'react-native';
import { useNavigation } from '@react-navigation/native';
import { GlobalStyles } from '../styles/GlobalStyles';
import { auth } from '../../firebase';
import { signOut } from 'firebase/auth';

export default function Home() {
    const [userEmail, setUserEmail] = useState('');
    const navigation = useNavigation();

    //set useremail to present
    useEffect(() =&amp;gt; {
      const user = auth.currentUser;
      if (user) {
          setUserEmail(user.email);
      }
  }, []);

    // logout the user
    const handleLogout = () =&amp;gt; {
      signOut(auth).then(() =&amp;gt; {
        navigation.navigate('Login');
      }).catch((error) =&amp;gt; {
        Alert.alert('Logout Failed', error.message);
      });
    };
    return (
      &amp;lt;SafeAreaView style={GlobalStyles.screenContainer}&amp;gt;
        &amp;lt;Text&amp;gt;Welcome to the Home Screen, {userEmail}!&amp;lt;/Text&amp;gt;
        &amp;lt;TouchableOpacity style={GlobalStyles.button} onPress={handleLogout}&amp;gt;
          &amp;lt;Text style={GlobalStyles.buttonText}&amp;gt;Sign Out&amp;lt;/Text&amp;gt;
        &amp;lt;/TouchableOpacity&amp;gt;
      &amp;lt;/SafeAreaView&amp;gt;
    );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After clicking the Signout button the user is signed out and the login screen becomes visible.&lt;/p&gt;

&lt;h2&gt;
  
  
  Login
&lt;/h2&gt;

&lt;p&gt;For the login, implement similar form validation and submission, and on submit utilize the &lt;code&gt;login&lt;/code&gt; function from firebase.&lt;/p&gt;

&lt;p&gt;Add new imports&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Formik } from 'formik';
import * as yup from 'yup';
import { auth } from '../../firebase';
import { signInWithEmailAndPassword } from 'firebase/auth';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the login implementation to &lt;code&gt;handleLogin&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const handleLoginPress = (values) =&amp;gt; {
        signInWithEmailAndPassword(auth, values.email, values.password)
            .then((userCredential) =&amp;gt; {
                console.log('Logged in:', userCredential.user);
                navigation.navigate('Home');
            })
            .catch((error) =&amp;gt; {
                Alert.alert('Authentication Failed', error.message);
            });
    };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the credentials are correct the user should be logged in to the home screen after pressing the login button.&lt;/p&gt;

&lt;p&gt;For the full document please check &lt;a href="https://github.com/Balogh08/CodePlayground/blob/email_auth_setup/src/screens/Login.js" rel="noopener noreferrer"&gt;Login.js&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conditional Navigation Based on Authentication State
&lt;/h2&gt;

&lt;p&gt;One more thing to add. Home screen should be available only to authenticated users and the back to &lt;code&gt;login&lt;/code&gt; button from the Home.js top left corner should be removed. Not authenticated users should only see login and signup screens.&lt;/p&gt;

&lt;p&gt;For this 2 &lt;code&gt;Stack.Navigator&lt;/code&gt; and &lt;code&gt;auth.onAuthStateChanged&lt;/code&gt; functions can be utilized.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState, useEffect } from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { SafeAreaProvider, SafeAreaView } from 'react-native-safe-area-context';
import { auth } from './firebase';
import Login from './src/screens/Login';
import Signup from './src/screens/Signup';
import Home from './src/screens/Home';

const Stack = createNativeStackNavigator();

function App() {
  const [isAuthenticated, setIsAuthenticated] = useState(false);

  // Check if user is authenticated
  useEffect(() =&amp;gt; {
    const unsubscribe = auth.onAuthStateChanged(user =&amp;gt; {
      setIsAuthenticated(!!user);
    });

    return () =&amp;gt; unsubscribe();
  }, []);

  return (
      &amp;lt;SafeAreaProvider&amp;gt;
        &amp;lt;SafeAreaView style={{ flex: 1 }}&amp;gt;
          &amp;lt;NavigationContainer&amp;gt;
            {isAuthenticated ? (
              &amp;lt;Stack.Navigator&amp;gt;
                &amp;lt;Stack.Screen name="Home" component={Home} /&amp;gt;
              &amp;lt;/Stack.Navigator&amp;gt;
            ) : (
              &amp;lt;Stack.Navigator initialRouteName="Login"&amp;gt;
                &amp;lt;Stack.Screen name="Login" component={Login} /&amp;gt;
                &amp;lt;Stack.Screen name="Signup" component={Signup} /&amp;gt;
              &amp;lt;/Stack.Navigator&amp;gt;
            )}
          &amp;lt;/NavigationContainer&amp;gt;
        &amp;lt;/SafeAreaView&amp;gt;
      &amp;lt;/SafeAreaProvider&amp;gt;
  );
}

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check out the final code &lt;a href="https://github.com/Balogh08/CodePlayground/tree/email_auth_setup" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Thank you for reading.&lt;/p&gt;

&lt;h2&gt;
  
  
  Additional Features and Improvements
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Visibility icon for password.&lt;/li&gt;
&lt;li&gt;Password change option.&lt;/li&gt;
&lt;li&gt;Sign up with Facebook, Google, and Apple.&lt;/li&gt;
&lt;li&gt;Adding custom components.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://rnfirebase.io/auth/usage" rel="noopener noreferrer"&gt;https://rnfirebase.io/auth/usage&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://reactnative.dev/docs/environment-setup?guide=native&amp;amp;platform=ios" rel="noopener noreferrer"&gt;https://reactnative.dev/docs/environment-setup?guide=native&amp;amp;platform=ios&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.atomlab.dev/tutorials/integrating-firebase-react-native" rel="noopener noreferrer"&gt;https://www.atomlab.dev/tutorials/integrating-firebase-react-native&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.atomlab.dev/tutorials/email-authentication-react-native-firebase" rel="noopener noreferrer"&gt;https://www.atomlab.dev/tutorials/email-authentication-react-native-firebase&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@adityasinghrathore360/implementing-firebase-authentication-in-react-native-app-with-expo-a-detailed-explanation-cea4d1113501" rel="noopener noreferrer"&gt;https://medium.com/@adityasinghrathore360/implementing-firebase-authentication-in-react-native-app-with-expo-a-detailed-explanation-cea4d1113501&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;More about the author at &lt;a href="//www.lunitech.hu"&gt;LUNitECH&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
