<?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: Karan Choudhary</title>
    <description>The latest articles on DEV Community by Karan Choudhary (@karanchoudhary).</description>
    <link>https://dev.to/karanchoudhary</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%2F588908%2F54f2a331-69e5-4b99-bf8b-d8d3082d4a1c.png</url>
      <title>DEV Community: Karan Choudhary</title>
      <link>https://dev.to/karanchoudhary</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/karanchoudhary"/>
    <language>en</language>
    <item>
      <title>Setting up Google Authentication With Firebase🚀</title>
      <dc:creator>Karan Choudhary</dc:creator>
      <pubDate>Tue, 08 Jun 2021 13:03:00 +0000</pubDate>
      <link>https://dev.to/karanchoudhary/setting-up-google-authentication-with-firebase-n6i</link>
      <guid>https://dev.to/karanchoudhary/setting-up-google-authentication-with-firebase-n6i</guid>
      <description>&lt;h1&gt;
  
  
  A Bit About Me
&lt;/h1&gt;

&lt;p&gt;Hey folks👋🏻, I am Karan Choudhary. A frontend developer passionate about web technologies and building things with code💻.&lt;/p&gt;

&lt;p&gt;In this article, we will learn the easiest and the fastest way to setup Google Authentication with Firebase. So without wasting any time, let's get straight into it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Firebase Authentication?
&lt;/h2&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%2Ffirebase.google.com%2Fdocs%2Fauth%2Fimages%2Fauth-providers.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%2Ffirebase.google.com%2Fdocs%2Fauth%2Fimages%2Fauth-providers.png" alt="firebase"&gt;&lt;/a&gt;&lt;br&gt;
Most apps need to know the identity of a user. Knowing a user's identity allows an app to securely save user data in the cloud and provide the same personalized experience across all of the user's devices.&lt;/p&gt;

&lt;p&gt;Firebase Authentication provides backend services, easy-to-use SDKs, and ready-made UI libraries to authenticate users to your app. It supports authentication using passwords, phone numbers, popular federated identity providers like Google, Facebook and Twitter, and more.&lt;/p&gt;

&lt;p&gt;Firebase Authentication integrates tightly with other Firebase services, and it leverages industry standards like OAuth 2.0 and OpenID Connect, so it can be easily integrated with your custom backend.&lt;/p&gt;
&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;p&gt;Since we'll be needing some starter files for that. I've published a NPM package for easy build setup. Or else you can just clone the GitHub Repository. &lt;/p&gt;
&lt;h2&gt;
  
  
  Installation⚒️
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;You’ll need to have Node 10.16.0 or later version on your local development machine&lt;/strong&gt;. I recommend using the latest LTS version.&lt;/p&gt;

&lt;p&gt;To create a new app, you may choose one of the following methods:&lt;/p&gt;
&lt;h3&gt;
  
  
  npm
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Install the package
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i firebase-auth-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Create a project using Firebase-Auth-App CLI
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;firebase-auth-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Install dependencies
&lt;/li&gt;
&lt;/ol&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;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  git
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Clone the repository
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone git@github.com:itskaranchoudhary/firebase-auth-app.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Change the working directory
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;firebase-auth-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Install dependencies
&lt;/li&gt;
&lt;/ol&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;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;It will create a directory called &lt;code&gt;firebase-auth-app&lt;/code&gt; inside the current folder.&lt;br&gt;&lt;br&gt;
Inside that directory, it will generate the following project structure and install the required dependencies.&lt;/p&gt;
&lt;h2&gt;
  
  
  File Structure
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;├── src/
│   └── assets
│   └── scripts
│   └── styles
│   └──favicon.ico
├── .gitignore
├── firebase.json
├── index.html
├── package-lock.json
└── package.json
├── README.md
├── LICENSE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Creating a Firebase Project
&lt;/h2&gt;

&lt;p&gt;First of all, go to you  &lt;a href="https://console.firebase.google.com/" rel="noopener noreferrer"&gt;firebase console&lt;/a&gt; and Create a new project. &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%2Ffirebasestorage.googleapis.com%2Fv0%2Fb%2Furl-creator-2ee08.appspot.com%2Fo%2FScreenshot%2520%2528133%2529.png%3Falt%3Dmedia%26token%3D13a60363-85d2-4cb5-be77-2b37976816c2" 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%2Ffirebasestorage.googleapis.com%2Fv0%2Fb%2Furl-creator-2ee08.appspot.com%2Fo%2FScreenshot%2520%2528133%2529.png%3Falt%3Dmedia%26token%3D13a60363-85d2-4cb5-be77-2b37976816c2" alt="enter image description here"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After creating a project, click on  &lt;strong&gt;Web&lt;/strong&gt;  button to register your web app.  &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffirebasestorage.googleapis.com%2Fv0%2Fb%2Furl-creator-2ee08.appspot.com%2Fo%2FScreenshot%2520%2528134%2529.png%3Falt%3Dmedia%26token%3Df924455a-9a98-4495-a3fc-32be862a16d9" 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%2Ffirebasestorage.googleapis.com%2Fv0%2Fb%2Furl-creator-2ee08.appspot.com%2Fo%2FScreenshot%2520%2528134%2529.png%3Falt%3Dmedia%26token%3Df924455a-9a98-4495-a3fc-32be862a16d9" alt="enter image description here"&gt;&lt;/a&gt;&lt;br&gt;
Enter the name of your web app and that's it.&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%2Ffirebasestorage.googleapis.com%2Fv0%2Fb%2Furl-creator-2ee08.appspot.com%2Fo%2FScreenshot%2520%2528136%2529.png%3Falt%3Dmedia%26token%3D81b565eb-30da-419d-92cd-2e02b4b7d1db" 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%2Ffirebasestorage.googleapis.com%2Fv0%2Fb%2Furl-creator-2ee08.appspot.com%2Fo%2FScreenshot%2520%2528136%2529.png%3Falt%3Dmedia%26token%3D81b565eb-30da-419d-92cd-2e02b4b7d1db" alt="enter image description here"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Enabling Google Authentication
&lt;/h2&gt;

&lt;p&gt;Since you have added the web app, enable the Google Sign-Up Method under the &lt;code&gt;Authentication/Sign-In Method/Sign-In Providers&lt;/code&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%2Ffirebasestorage.googleapis.com%2Fv0%2Fb%2Furl-creator-2ee08.appspot.com%2Fo%2FScreenshot%2520%2528128%2529.png%3Falt%3Dmedia%26token%3Dc004aaad-3a8f-4f17-b725-fb86a58b6787" 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%2Ffirebasestorage.googleapis.com%2Fv0%2Fb%2Furl-creator-2ee08.appspot.com%2Fo%2FScreenshot%2520%2528128%2529.png%3Falt%3Dmedia%26token%3Dc004aaad-3a8f-4f17-b725-fb86a58b6787" alt="enter image description here"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Adding the Authorized Domain
&lt;/h2&gt;

&lt;p&gt;Since Firebase Auth doesn't work with live server. You'll have to manually add the domain you would be deploying your app to. &lt;/p&gt;

&lt;p&gt;Go to &lt;code&gt;Authentication/Sign-In Method/Authorized Domains&lt;/code&gt;add your domain. &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%2Ffirebasestorage.googleapis.com%2Fv0%2Fb%2Furl-creator-2ee08.appspot.com%2Fo%2FScreenshot%2520%2528131%2529.png%3Falt%3Dmedia%26token%3Da3819431-0098-40c3-a67f-4be041c94b30" 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%2Ffirebasestorage.googleapis.com%2Fv0%2Fb%2Furl-creator-2ee08.appspot.com%2Fo%2FScreenshot%2520%2528131%2529.png%3Falt%3Dmedia%26token%3Da3819431-0098-40c3-a67f-4be041c94b30" alt="enter image description here"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Firebase Config
&lt;/h2&gt;

&lt;p&gt;Now, go to  &lt;strong&gt;Project Settings &amp;gt; SDK Setup and Configuration&lt;/strong&gt;  to get your  &lt;code&gt;firebaseConfig&lt;/code&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%2Ffirebasestorage.googleapis.com%2Fv0%2Fb%2Furl-creator-2ee08.appspot.com%2Fo%2FScreenshot%2520%2528140%2529.png%3Falt%3Dmedia%26token%3Db80615bf-d03d-41f3-b03b-2f4a6f3caa48" 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%2Ffirebasestorage.googleapis.com%2Fv0%2Fb%2Furl-creator-2ee08.appspot.com%2Fo%2FScreenshot%2520%2528140%2529.png%3Falt%3Dmedia%26token%3Db80615bf-d03d-41f3-b03b-2f4a6f3caa48" alt="enter image description here"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It should look something 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;var firebaseConfig = {
    apiKey: "API_KEY",
    authDomain: "PROJECT_ID.firebaseapp.com",
    databaseURL: "https://PROJECT_ID.firebaseio.com",
    projectId: "PROJECT_ID",
    storageBucket: "PROJECT_ID.appspot.com",
    messagingSenderId: "SENDER_ID",
    appId: "APP_ID",
    measurementId: "G-MEASUREMENT_ID",
  };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Copy the config and paste it into &lt;code&gt;index.html &amp;gt; script tag&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;🌟 You are all set!&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing the App
&lt;/h2&gt;

&lt;p&gt;To test the app, we need to deploy it to the domain we have added in the firebase console. &lt;/p&gt;

&lt;p&gt;Since, I have already deployed my app. I can visit &lt;a href="https://friendlychatapp.netlify.app" rel="noopener noreferrer"&gt;https://friendlychatapp.netlify.app&lt;/a&gt; to check if the authentication is working properly or not.&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%2Ffirebasestorage.googleapis.com%2Fv0%2Fb%2Furl-creator-2ee08.appspot.com%2Fo%2FScreenshot%2520%2528145%2529.png%3Falt%3Dmedia%26token%3Da725f12f-2140-42cf-b3b4-65bb1f8d2312" 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%2Ffirebasestorage.googleapis.com%2Fv0%2Fb%2Furl-creator-2ee08.appspot.com%2Fo%2FScreenshot%2520%2528145%2529.png%3Falt%3Dmedia%26token%3Da725f12f-2140-42cf-b3b4-65bb1f8d2312" alt="enter image description here"&gt;&lt;/a&gt;&lt;br&gt;
And it seems like everything is working fine.✔&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%2Ffirebasestorage.googleapis.com%2Fv0%2Fb%2Furl-creator-2ee08.appspot.com%2Fo%2FScreenshot%2520%2528146%2529.png%3Falt%3Dmedia%26token%3Dd93f2edd-1b1b-403d-a8bf-79266acfcf7d" 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%2Ffirebasestorage.googleapis.com%2Fv0%2Fb%2Furl-creator-2ee08.appspot.com%2Fo%2FScreenshot%2520%2528146%2529.png%3Falt%3Dmedia%26token%3Dd93f2edd-1b1b-403d-a8bf-79266acfcf7d" alt="enter image description here"&gt;&lt;/a&gt;&lt;br&gt;
Now, go to &lt;a href="https://console.firebase.google.com/" rel="noopener noreferrer"&gt;firebase console&lt;/a&gt; and open up your firebase project and go to &lt;strong&gt;Authentication &amp;gt; Users&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%2Ffirebasestorage.googleapis.com%2Fv0%2Fb%2Furl-creator-2ee08.appspot.com%2Fo%2FScreenshot%2520%2528147%2529.png%3Falt%3Dmedia%26token%3Dd7416d4a-e412-487d-964d-34ab5421b10a" 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%2Ffirebasestorage.googleapis.com%2Fv0%2Fb%2Furl-creator-2ee08.appspot.com%2Fo%2FScreenshot%2520%2528147%2529.png%3Falt%3Dmedia%26token%3Dd7416d4a-e412-487d-964d-34ab5421b10a" alt="enter image description here"&gt;&lt;/a&gt;&lt;br&gt;
We can see a that a new user is added✨.&lt;/p&gt;

&lt;p&gt;Let's do another check by logging the user details in the console using &lt;code&gt;console.log()&lt;/code&gt;&lt;br&gt;
Copy and paste the following code in the console:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var user = firebase.auth().currentUser;
var name, email, photoUrl, uid, emailVerified;

if (user != null) {  
    name = user.displayName;  
    email = user.email;  
    photoUrl = user.photoURL;  
    emailVerified = user.emailVerified;  
    uid = user.uid;  // The user's ID, unique to the Firebase project. 
    }

console.log(name, email, uid);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If everything is right it should log my details in the console. &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%2Ffirebasestorage.googleapis.com%2Fv0%2Fb%2Furl-creator-2ee08.appspot.com%2Fo%2FScreenshot%2520%2528148%2529.png%3Falt%3Dmedia%26token%3Dca41b27f-31bc-4468-902e-ea3415555dea" 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%2Ffirebasestorage.googleapis.com%2Fv0%2Fb%2Furl-creator-2ee08.appspot.com%2Fo%2FScreenshot%2520%2528148%2529.png%3Falt%3Dmedia%26token%3Dca41b27f-31bc-4468-902e-ea3415555dea" alt="enter image description here"&gt;&lt;/a&gt;&lt;br&gt;
That's pretty much it! Congratulations. You've just setup Google Authentication using Firebase🥳&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap Up
&lt;/h2&gt;

&lt;p&gt;So that's it. Hope you enjoyed the article. Feel free to share your thoughts in the comment section below. Any feedback is greatly appreciated.&lt;/p&gt;

&lt;p&gt;Feel free to the check out my GitHub: &lt;a href="https://github.com/itskaranchoudhary" rel="noopener noreferrer"&gt;https://github.com/itskaranchoudhary&lt;/a&gt;&lt;br&gt;&lt;br&gt;
Star the repo⭐: &lt;a href="https://github.com/itskaranchoudhary/firebase-auth-app" rel="noopener noreferrer"&gt;https://github.com/itskaranchoudhary/firebase-auth-app&lt;/a&gt;&lt;br&gt;&lt;br&gt;
Find the NPM Package here: &lt;a href="https://www.npmjs.com/package/firebase-auth-app" rel="noopener noreferrer"&gt;https://www.npmjs.com/package/firebase-auth-app&lt;/a&gt;&lt;/p&gt;




</description>
      <category>firebase</category>
      <category>authentication</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
