<?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: Ashutosh Dubey</title>
    <description>The latest articles on DEV Community by Ashutosh Dubey (@dubeyji).</description>
    <link>https://dev.to/dubeyji</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%2F682707%2F5118a29d-6d9b-4921-a8be-870fa79bcb2f.jpeg</url>
      <title>DEV Community: Ashutosh Dubey</title>
      <link>https://dev.to/dubeyji</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dubeyji"/>
    <language>en</language>
    <item>
      <title>Connecting React App to firebase</title>
      <dc:creator>Ashutosh Dubey</dc:creator>
      <pubDate>Thu, 21 Oct 2021 04:38:57 +0000</pubDate>
      <link>https://dev.to/dubeyji/connecting-react-app-to-firebase-4jbg</link>
      <guid>https://dev.to/dubeyji/connecting-react-app-to-firebase-4jbg</guid>
      <description>&lt;h2&gt;
  
  
  Create React App
&lt;/h2&gt;

&lt;p&gt;Open your terminal and go to the directory or location where you want to create the app. Run this command&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;npx create-react-app firebasetut&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Go into the app directory by command&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;cd firebasetut&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Install firebase module
&lt;/h2&gt;

&lt;p&gt;Run this command in your terminal to install firebase module&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;npm i firebase&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It will take some time to install. After it get install check your &lt;strong&gt;package.json&lt;/strong&gt; file and in the dependencies section you will find Firebase with all other dependencies.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create app in Firebase console
&lt;/h2&gt;

&lt;p&gt;Go to &lt;a href="https://console.firebase.google.com"&gt;firebase console&lt;/a&gt;&lt;br&gt;
Give name of your first project and than click &lt;strong&gt;continue&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--15HlY-dT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gcu7r65h7sb3cyzuk79o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--15HlY-dT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gcu7r65h7sb3cyzuk79o.png" alt="Firebase Console Step 1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Disable Google analytics and than click on &lt;strong&gt;create project&lt;/strong&gt;. (&lt;em&gt;It's optional if you want to keep it enable than keep it enable and create project&lt;/em&gt;). It will take sometime to create project. Just wait and you will see the another screen. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--R3KHH7d2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rmvdykknb3tryj107tx3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--R3KHH7d2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rmvdykknb3tryj107tx3.png" alt="Firebase Console Step 2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Register you app
&lt;/h2&gt;

&lt;p&gt;Click on the &lt;strong&gt;web symbol&lt;/strong&gt; to register your app for web.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pKGzphYl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g3rp9ub728xl021rl749.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pKGzphYl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g3rp9ub728xl021rl749.png" alt="App Register"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Than give your app a &lt;strong&gt;name&lt;/strong&gt; and &lt;strong&gt;register it&lt;/strong&gt;. After it get registered you will see the &lt;strong&gt;configuration code&lt;/strong&gt; for your app copy that code. So that we can use it in our react app.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ms0P7uvd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mj02eo2tak0s5q8mn75l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ms0P7uvd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mj02eo2tak0s5q8mn75l.png" alt="App SDK"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding Configuration code to react app
&lt;/h2&gt;

&lt;p&gt;Open any code editor. I'm using &lt;a href="https://code.visualstudio.com%20%E2%80%BA%20download"&gt;vscode&lt;/a&gt;. You can clone this &lt;a href="https://github.com/dubey-Ji/Firebase_tutuorial/tree/main"&gt;repository&lt;/a&gt; to start the project.&lt;/p&gt;

&lt;p&gt;In your &lt;strong&gt;src folder&lt;/strong&gt; create new file name &lt;strong&gt;firebase-config.js&lt;/strong&gt;&lt;br&gt;
After creating this file. &lt;strong&gt;File structure&lt;/strong&gt; of your app will look like this.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ILu6vAMU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nouowqozyr9ng8cbbf2n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ILu6vAMU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nouowqozyr9ng8cbbf2n.png" alt="File Structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Paste that &lt;strong&gt;configuration code&lt;/strong&gt; which we copied from the firebase console after registering our app. And &lt;strong&gt;very important add the export before const app&lt;/strong&gt;. So that we can import that app variable in other file.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pVMJZibG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xv5v6p9urbpj8kz6e8by.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pVMJZibG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xv5v6p9urbpj8kz6e8by.png" alt="Firebase Config Code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Your React App is connected to firebase&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Additional
&lt;/h2&gt;

&lt;p&gt;If you want you can store the configuration file apikey and other variable values in .env file(&lt;em&gt;It's a good practice to follow before making your code public&lt;/em&gt;). Create config.env file in firebasetut folder(&lt;strong&gt;in main root folder&lt;/strong&gt;).&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IjHjbLF---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ocosqi90aqbj2u4mibyk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IjHjbLF---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ocosqi90aqbj2u4mibyk.png" alt="Config.env file"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And make variable like shown in image. If you are creating any variable in .env file of react app you have to follow this convention &lt;strong&gt;REACT_APP_VARIABLENAME&lt;/strong&gt;&lt;br&gt;
After you have done adding all the values in config.env file. Change your firebase-config.js file code. Instead of value write this variable which you have created in config.env file.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--A0t_GPkr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nfrm2lcrgjakv67vssbs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A0t_GPkr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nfrm2lcrgjakv67vssbs.png" alt="Firebase Config File"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally we have done connecting our react app to Firebase and can make our code public.&lt;/p&gt;

</description>
      <category>firebase</category>
      <category>react</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
