← Back to resources

March 2, 2026 • Parth Narkar

How to Easily Use Firebase Google Authentication in Your Project

A step-by-step guide to integrating Google Authentication using Firebase in your web project, from setup to implementation.

This guide will help you integrate Google Authentication using Firebase in your web project (React example included).


Why Use Firebase Google Auth?

  • No password handling
  • Secure OAuth handled by Google
  • Easy integration
  • Trusted by users
  • Free tier is enough for most projects

Step-by-Step Implementation


Step 1: Create a Firebase Project

  1. Go to: https://console.firebase.google.com
  2. Click Add Project
  3. Enter project name
  4. Disable Google Analytics (optional)
  5. Click Create Project

Step 2: Enable Google Authentication

  1. Go to Authentication
  2. Click Get Started
  3. Open Sign-in method
  4. Enable Google
  5. Add your support email
  6. Save

Done. Google login is now enabled.


Step 3: Register Your Web App

  1. Go to Project Settings
  2. Click Add App (Web icon </>)
  3. Enter app nickname
  4. Click Register App
  5. Copy the Firebase config object

It will look like this:

const firebaseConfig = {
  apiKey: "XXXX",
  authDomain: "XXXX.firebaseapp.com",
  projectId: "XXXX",
  storageBucket: "XXXX.appspot.com",
  messagingSenderId: "XXXX",
  appId: "XXXX"
};

Step 4: Install Firebase in Your Project

npm install firebase

Step 5: Initialize Firebase

Create a file: firebase.js

import { initializeApp } from "firebase/app";
import { getAuth, GoogleAuthProvider } from "firebase/auth";

const firebaseConfig = {
  apiKey: "XXXX",
  authDomain: "XXXX.firebaseapp.com",
  projectId: "XXXX",
  storageBucket: "XXXX.appspot.com",
  messagingSenderId: "XXXX",
  appId: "XXXX"
};

const app = initializeApp(firebaseConfig);

export const auth = getAuth(app);
export const provider = new GoogleAuthProvider();

Step 6: Add Google Sign-In Function

Example (React):

import { signInWithPopup } from "firebase/auth";
import { auth, provider } from "./firebase";

const handleGoogleLogin = async () => {
  try {
    const result = await signInWithPopup(auth, provider);
    console.log(result.user);
  } catch (error) {
    console.error(error);
  }
};

Step 7: Add Logout Function

import { signOut } from "firebase/auth";
import { auth } from "./firebase";

const handleLogout = async () => {
  await signOut(auth);
};

Step 8: Listen to Auth State Changes (Very Important)

This keeps user logged in after refresh.

import { onAuthStateChanged } from "firebase/auth";
import { auth } from "./firebase";

useEffect(() => {
  const unsubscribe = onAuthStateChanged(auth, (user) => {
    if (user) {
      console.log("Logged in:", user);
    } else {
      console.log("Logged out");
    }
  });

  return () => unsubscribe();
}, []);

Protect Routes (Basic Idea)

If user exists → show dashboard If not → redirect to login page

You can use:

  • React conditional rendering
  • React Router protected routes

Common Mistakes

  • Forgetting to enable Google provider
  • Not adding your domain in authorized domains
  • Not handling auth state on refresh
  • Exposing Firebase config in public repo without security rules

Pro Tip

If you want:

  • Store user data → Use Firestore
  • Add role-based access → Store role in Firestore
  • Improve UX → Show profile photo and name from result.user

What You Get from Google Auth

After login, Firebase gives:

  • Name
  • Email
  • Profile picture
  • UID (unique user id)
  • Access token

You don’t need to build auth logic from scratch.


When Should You Use Google Auth?

  • SaaS projects
  • Hackathon projects
  • Internal tools
  • Portfolio projects
  • MVPs

Avoid building custom auth unless absolutely needed.