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
- Go to: https://console.firebase.google.com
- Click Add Project
- Enter project name
- Disable Google Analytics (optional)
- Click Create Project
Step 2: Enable Google Authentication
- Go to Authentication
- Click Get Started
- Open Sign-in method
- Enable Google
- Add your support email
- Save
Done. Google login is now enabled.
Step 3: Register Your Web App
- Go to Project Settings
- Click Add App (Web icon
</>) - Enter app nickname
- Click Register App
- 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
- 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.