<?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: Bunyameen Nurudeen Shola</title>
    <description>The latest articles on DEV Community by Bunyameen Nurudeen Shola (@shollytemmy).</description>
    <link>https://dev.to/shollytemmy</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%2F746079%2F2fe55732-8ee5-41ad-9f69-70699630b4b6.jpg</url>
      <title>DEV Community: Bunyameen Nurudeen Shola</title>
      <link>https://dev.to/shollytemmy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shollytemmy"/>
    <language>en</language>
    <item>
      <title>Novice Guide to Securing API and Firebase Key In React Vite using dotenv(Environment Veriable).</title>
      <dc:creator>Bunyameen Nurudeen Shola</dc:creator>
      <pubDate>Sat, 07 Oct 2023 10:18:20 +0000</pubDate>
      <link>https://dev.to/shollytemmy/novice-guide-to-securing-api-and-firebase-key-in-react-vite-using-dotenvenvironment-veriable-2554</link>
      <guid>https://dev.to/shollytemmy/novice-guide-to-securing-api-and-firebase-key-in-react-vite-using-dotenvenvironment-veriable-2554</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1hX1OWPU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ibui7v0bmfd6qe2gylp9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1hX1OWPU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ibui7v0bmfd6qe2gylp9.png" alt="Image description" width="332" height="152"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Recently I was trying to work on a web project to track each user's progress on &lt;a href="https://www.freecodecamp.org/"&gt;Freecodecamp&lt;/a&gt; platform to get / fetch their point using React Vite and Firebase just to practice ReactJs and integrate firebase to add more functionality.&lt;/p&gt;

&lt;p&gt;My goal was to secure the Api Key by preventing it from pushing it to Github. I researched on getting this done and i decided to document it because this can help others who will be looking for a way to achieve same goal using &lt;a href="https://vitejs.dev/guide/#overview"&gt;Vite&lt;/a&gt; since the way to achieve this with &lt;a href="https://vitejs.dev/guide/#overview"&gt;Vite&lt;/a&gt; different from using create-react-app.&lt;/p&gt;

&lt;p&gt;These are the following steps to achieve the goal.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Just create a .env file at  the root of the folder/ project and add all your API key as below example. Ensure you start with the VITE word.( E.g, VITE_SOME_KEY=123). (step 1)
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;VITE_FIREBASE_API_KEY=AIzaSyAlL9BFqrGofCzlcJQOdSATQWSCpU8RybM
VITE_FIREBASE_AUTH_DOMAIN=advanced-login-signup.firebaseapp.com
VITE_FIREBASE_PROJECT_ID=advanced-login-signup
VITE_FIREBASE_STORAGE_BUCKET=advanced-login-signup.appspot.com
VITE_FIREBASE_MESSAGING_SENDER_ID=71315803652
VITE_FIREBASE_APP_ID=1:71315803652:web:db96ed49092ea0824daf51

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

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Make sure you add .env file in .gitignore to prevent it from pushing on to the GitHub.(step 2)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To use the key just use it like below code snippet. This is my firebase.js file.(step 3)&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {getAuth} from "firebase/auth"
import { initializeApp } from "firebase/app";

const firebaseConfig = {
  apiKey: import.meta.env.VITE_FIREBASE_API_KEY,
  authDomain: import.meta.env.VITE_FIREBASE_AUTH_DOMAIN,
  projectId: import.meta.env.VITE_FIREBASE_PROJECT_ID,
  storageBucket: import.meta.env.VITE_FIREBASE_STORAGE_BUCKET,
  messagingSenderId: import.meta.env.VITE_FIREBASE_MESSAGING_SENDER_ID,
  appId: import.meta.env.VITE_API_ID
};

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

&lt;/div&gt;



&lt;p&gt;Now understand that to use the variable names from .env file in our firebase.js file we make use of import.meta.env.VITE_SOME_KEY.&lt;/p&gt;

&lt;p&gt;Congratulation we just secure our Api Key from exposing and pushing  it to Github.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>api</category>
      <category>database</category>
    </item>
  </channel>
</rss>
