This website uses cookies to ensure you get the best experience on our website.

Skip to content
LOGO
  • Company

    About IGNEK

    Learn about our story and our mission.

    Careers

    We're hiring!

    We always looking for talented peoples. Join our team!

    Blogs

    The latest industry news, updates and info.

    Case Studies

    Take a closer look at the projects we've delivered

    Webinar

    Watch our latest organized webinar

    Get in touch with our HR team

    • hr@insights.ignek.com
    • +91 93284 95160
    • Ahmedabad, Gujarat, India – 382470
  • Services

    Enterprise Portal Development

    Custom Enterprise Portal Development for flawless Solutions

    Dedicated Development Team

    Expand Teams, Optimize Development with Our Expertise

    Back-end Development

    Empowering your digital presence with robust backend development expertise

    Front-end Development

    Crafting engaging user experiences through expert frontend development

    Digital Transformation

    Embrace digital transformation by modernizing process

    SaaS Development

    Transform your business with SaaS Innovative Solutions

    Technologies

    Liferay Services

    Development & Customization

    Theme

    Upgradation

    Migration

    Proof of Concept

    Performance Tunning

    Architecture

    Support & Maintenance

    E-commerce

    Expert Advice

    React Services

    Enterprise Development

    Custom Application

    Single Page Application

    Architecture

    API Integration

    Migration

    Consulting

    Maintenance & Support

    Spring Boot Services

    Web Service

    MVC Web Development

    API Integration

    Security

    Migration

    Microservices

    Support & Maintenance

    AEM Services

    Consulting Service

    Site Development

    Migration & Upgradation

    Integration

    Maintenance & Support

    Custom Solutions

    Content Management

    Team Augementation

  • Solution

    Ready for digital excellence

    In our rapidly evolving world, businesses are always on the lookout for fresh ways to improve their operations and connect with their audiences.

    Contact US

    Solutions

    SaaS : Software As A Service

    Transforming industries through cutting edge SaaS solutions.

    Customer Portal : Boost Business Productivity

    Streamline operations and enhance productivity with our Customer Portal solution.

    Liferay Based Intranet Portal

    Internal portal for company communication, collaboration and resources

    Integration

    Matomo Integration with Liferay

    Integrate Matomo to enable user interactions seamlessly.

    Microsoft Teams integration with Liferay

    Integrate to enable seamless collaboration, messaging within your portal.

    Jira Integration With Liferay

    Optimizes business operations by integrating with Jira.

  • Hire Us

    Liferay

    Get expert Liferay developers for seamless portal solutions.

    React JS

    Get expert ReactJS developers for dynamic web solutions.

    Web Developer

    Get custom web solutions from IGNEK's expert developers.

    Spring Boot

    Get top-notch Spring Boot developers for your project success!

    Healthcare

    Get top Healthcare Developers for cutting-edge medical software.

    MERN Stack

    Get expert MERN developers from IGNEK for custom, innovative project solutions.

    Why Hire Developers From IGNEK ?

    • Certified Developer
    • Transparent Communication
    • Flexible Hiring Modals
    • Fully Signed NDA
    • Cost Effective
    • Easy Exit Policy

    Get in touch with our Sales team

    • sales@insights.ignek.com
    • +91 6351576580
    • info@insights.ignek.com
    • Ahmedabad, Gujarat, India – 382470
SCHEDULE CALL
  • COMPANY
    • About
    • Case Studies
    • Blogs
    • Career
    • Webinar
  • SERVICES
    • Enterprise Portal Development
    • Dedicated Development Team
    • Back-end Development
    • Front-end Development
    • Digital Transformation
    • SaaS Development
  • SOLUTION
    • Customer Portal:  Boost Business Productivity
    • SaaS : Software as a Service
    • Liferay Based Employee Intranet Portal
  • TECHNOLOGY
    • Liferay Services
      • Liferay Development and Customization
      • Liferay Theme Development Service
      • Liferay DXP 7.4 Upgrade
      • Liferay Migration
      • Liferay Proof Of Concept
      • Liferay Performance Tuning
      • Liferay Architecture Design Service
      • Liferay Support And Maintenance Service
      • Liferay Ecommerce Development
      • Liferay Expert Advice
    • ReactJS Services
      • ReactJS Enterprise Application Development
      • ReactJS Custom Application Development
      • ReactJS Single Page Application Development (SPA)
      • ReactJS Applications Architecture
      • ReactJS API Integration
      • ReactJS Migration
      • ReactJS Consulting
      • ReactJS Maintenance and Support
    • Spring Boot Services
      • Spring Boot Web Development Service
      • Spring MVC Web Development
      • Spring Boot API Integration Service
      • Spring Boot Security
      • Spring Boot Migration Service
      • Spring Boot Microservices
      • Spring Boot Support & Maintenance Service
    • AEM Development Services
      • AEM Consulting Services
      • AEM Site Development
      • AEM Migration & Upgradation
      • AEM Integration Services
      • AEM Maintenance & Support
      • AEM Content Management
      • Custom AEM Solutions
      • AEM Team Augmentation
  • INTEGRATION
  • HIRE US
    • Hire Liferay Developer
    • Hire ReactJS Developer
    • Hire Spring Boot Developer
    • Hire Healthcare Developer
    • Hire Web Developer
    • Hire MERN Stack Developer
  • CONTACT US
  • Company

    About IGNEK

    Careers

    We're hiring!

    Blogs

    Case Studies

    Webinar

    Get in touch with our HR team

    • hr@insights.ignek.com
    • +91 93284 95160
    • Ahmedabad, Gujarat, India – 382470
  • Services

    Enterprise Portal Development

    Dedicated Development Team

    Back-end Development

    Front-end Development

    Digital Transformation

    SaaS Development

    Technologies

    Liferay Liferay Services
    • Development & Customization
    • Theme
    • Upgradation
    • Migration
    • Proof of Concept
    • Performance Tuning
    • Architecture
    • Support & Maintenance
    • E-commerce
    • Expert Advice
    React React Services
    • Enterprise Development
    • Custom Application
    • Single Page Application
    • Architecture
    • API Integration
    • Migration
    • Consulting
    • Maintenance & Support
    Spring Boot Spring Boot Services
    • Web Service
    • MVC Web Development
    • API Integration
    • Security
    • Migration
    • Microservices
    • Support & Maintenance
    AEM AEM Services
    • Consulting Service
    • Site Development
    • Migration & Upgradation
    • Integration
    • Maintenance & Support
    • Custom Solutions
    • Content Management
    • Team Augmentation
  • Solution

    Ready for digital excellence

    In our rapidly evolving world, businesses are always on the lookout for fresh ways to improve their operations and connect with their audiences.

    Contact US

    Solutions

    SaaS : Software As A Service

    Customer Portal : Boost Business Productivity

    Liferay Based Intranet Portal

    Integration

    Matomo Integration with Liferay

    Microsoft Teams integration with Liferay

    Jira Integration With Liferay

  • Hire Us

    Liferay

    React JS

    Web Developer

    Spring Boot

    Healthcare

    MERN Stack

    Why Hire Developers From IGNEK ?

    • Certified Developer
    • Transparent Communication
    • Flexible Hiring Modals
    • Fully Signed NDA
    • Cost Effective
    • Easy Exit Policy

    Get in touch with our Sales team

    • sales@insights.ignek.com
    • +91 6351576580
    • IGNEK
    • Ahmedabad, Gujarat, India – 382470
  • SCHEDULE CALL

Google, Facebook, and OTP Login Integration using Firebase in React : Part 1

  • ReactJS
  • November 25, 2025

Share On :

Introduction

User authentication is an important feature in all modern web applications. Whether they are e-commerce sites, social platforms, or business applications, web applications need to give users secure and convenient ways to log-in. In this three-part article, we are going to show you how to implement some of the popular logging-in methods by utilizing Firebase, React, TypeScript, and Material-UI. In Part One (this article), we are going to set up Google Authentication, which is the quickest way of allowing users to sign-in with their google account they already have, and by the end of this article we are going to have a working Google Sign-In in your React app.

Why Choose Firebase Authentication?

Firebase Authentication offers several advantages :

  • Easy Integration : Minimal setup required
  • Multiple Providers : Google, Facebook, Twitter, GitHub, and more
  • Security : Built-in security features and best practices
  • Scalability : Handles millions of users without additional configuration
  • Free Tier : Generous free usage limits
  • Real-time Updates : Instant authentication state changes
What will we create?

We will create a stunning UI as shown in this video, building it in three parts, so follow along till the end.

firebase-auth-demo
Prerequisites
  • Node.js (version 16 or higher) – Download here 
  • npm or yarn package manager
  • A Google account for Firebase Console access
  • Basic understanding of React and JavaScript/TypeScript
  • A code editor like VS Code

Don’t worry if you’re new to TypeScript or Firebase – we’ll explain everything step by step!

Setting Up Firebase

Step 1 : Create Your Firebase Project

  1. Visit the Firebase Console
  2. Click the “Create a project” button
  3. Enter a project name (e.g., “my-auth-app”)
  4. Choose whether to enable Google Analytics (recommended for production apps)
  5. Click “Create project” and wait for setup to complete

Step 2 : Enable Authentication Methods

  1. In your Firebase project dashboard, click “Authentication” in the left sidebar
  2. Go to the “Sign-in method” tab
  3. Enable the following providers:

For Google :

    • Click on “Google”.
    • Toggle “Enable”.
    • Select your project support email.
    • Click “Save”.

Step 3 : Get Your Firebase Configuration

  1. Click the gear icon ⚙️ next to “Project Overview”.
  2. Select “Project settings”.
  3. Scroll to “Your apps” section.
  4. Click the web icon </>.
  5. Register your app with a nickname.
  6. Copy the configuration object (we’ll use this later).
Creating the React TypeScript Project

Let’s create our project with all necessary dependencies :

				
					//Create a new react app using the following command
npm create vite@latest firebase-auth-demo -- --template react-ts

# Navigate to the project directory
cd firebase-auth-app

# Install required dependencies
npm install firebase @mui/material @emotion/react @emotion/styled @mui/icons-material @mui/lab

# Start the development server
npm run dev

				
			

Your browser should open automatically showing the default React app. If not, visit – http://localhost:5173.

Folder Structure :

				
					src/
├── components/
│   ├── auth/
│   │   ├── GoogleAuth.tsx
│   │   └── AuthenticationContainer.tsx
│   └── Dashboard.tsx
├── contexts/
│   └── AuthContext.tsx
├── services/
│   └── authService.ts
├── config/
│   └── firebase.ts
└── App.tsx

				
			
Firebase Configuration

Create src/config/firebase.ts :

				
					import { initializeApp } from 'firebase/app';
import { getAuth, GoogleAuthProvider} from 'firebase/auth';
import { getFirestore } from 'firebase/firestore';
const firebaseConfig = {
  apiKey: "your-api-key",
  authDomain: "your-project.firebaseapp.com",
  projectId: "your-project-id",
  storageBucket: "your-project.appspot.com",
  messagingSenderId: "your-sender-id",
  appId: "your-app-id"
};

// Initialize Firebase
const app = initializeApp(firebaseConfig);

// Initialize Firebase Authentication and get a reference to the service
export const auth = getAuth(app);

// Initialize Firestore
export const db = getFirestore(app);

// Configure providers
export const googleProvider = new GoogleAuthProvider();

export default app;

				
			
Authentication Service

Create src/services/authService.ts :

				
					import { signInWithPopup, type User, signOut as firebaseSignOut, onAuthStateChanged } from "firebase/auth";
import { auth, googleProvider } from '../config/firebase';

export interface AuthUser {
  uid: string;
  email: string | null;
  displayName: string | null;
  photoURL: string | null;
  phoneNumber: string | null;
}
class AuthService {
  // Google Sign In
  async signInWithGoogle(): Promise<AuthUser | null> {
    try {
      const result = await signInWithPopup(auth, googleProvider);
      return this.formatUser(result.user);
    } catch (error) {
      console.error('Google sign in error:', error);
      throw error;
    }
  }
  
 // Sign Out
  async signOut(): Promise<void> {
    try {
      await firebaseSignOut(auth);
      this.cleanup();
    } catch (error) {
      console.error('Sign out error:', error);
      throw error;
    }
  }

  // Listen to auth state changes
  onAuthStateChange(callback: (user: AuthUser | null) => void): () => void {
    return onAuthStateChanged(auth, (user) => {
      callback(user ? this.formatUser(user) : null);
    });
  }

  // Format user object
  private formatUser(user: User): AuthUser {
    return {
      uid: user.uid,
      email: user.email,
      displayName: user.displayName,
      photoURL: user.photoURL,
    };
  }
export default new AuthService();

				
			
Understanding Key Functions
  • signInWithPopup() :

This Firebase function opens a popup window for Google OAuth. It handles the entire OAuth flow and returns user credentials upon successful authentication.

  • onAuthStateChanged() :

A Firebase listener that monitors authentication state changes. It automatically updates your app when users sign in or out, ensuring consistent state management.

  • GoogleAuthProvider() :

Firebase’s built-in provider for Google OAuth. You can add specific scopes (like ’email’, ‘profile’) to request additional permissions.

  • Context Pattern:

React Context provides global authentication state management, avoiding prop drilling and ensuring any component can access user data.

  • Error Handling :

The implementation includes comprehensive error handling for common scenarios :

    • Popup blocked by browser
    • User cancels sign-in
    • Network connectivity issues
    • Invalid configurations
Authentication Context

Create src/contexts/AuthContext.tsx :

				
					import React, { createContext, useContext, useEffect, useState, type ReactNode } from 'react';
import authService, { type  AuthUser } from '../services/authService';

interface AuthContextType {
  user: AuthUser | null;
  loading: boolean;
  signInWithGoogle: () => Promise<void>;
  signOut: () => Promise<void>;
}

const AuthContext = createContext<AuthContextType | undefined>(undefined);

export const useAuth = (): AuthContextType => {
  const context = useContext(AuthContext);
  if (!context) {
    throw new Error('useAuth must be used within an AuthProvider');
  }
  return context;
};

interface AuthProviderProps {
  children: ReactNode;
}

export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
  const [user, setUser] = useState<AuthUser | null>(null);
  const [loading, setLoading] = useState<boolean>(true);

  useEffect(() => {
    const unsubscribe = authService.onAuthStateChange((user) => {
      setUser(user);
      setLoading(false);
    });

    return unsubscribe;
  }, []);

  const signInWithGoogle = async (): Promise<void> => {
    try {
      await authService.signInWithGoogle();
    } catch (error) {
      console.error('Google sign in failed:', error);
      throw error;
    }
  };

 const signOut = async (): Promise<void> => {
    try {
      await authService.signOut();
    } catch (error) {
      console.error('Sign out failed:', error);
      throw error;
    }
  };

  const value = { user, loading, signInWithGoogle, signOut };
  return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
};

				
			
Individual Authentication Components

GoogleAuth Component

Step 1 : Configure Google OAuth (Additional Setup)

  1. Visit Google Cloud Console

  2. Select your Firebase project

  3. Go to “APIs & Services” → “Credentials”

  4. Find your OAuth 2.0 Client ID (created automatically by Firebase)

  5. Add your development URL (http://localhost:3000) to “Authorized origins”

  6. For production, add your actual domain

Step 2 : Create Google Authentication Component

Create src/components/auth/GoogleAuth.tsx :

				
					// GoogleAuth.tsx
import { useAuth } from '../../contexts/AuthContext';
const GoogleAuth: React.FC = () => {
  const { signInWithGoogle } = useAuth();
 // here you can manage loading and errors etc.

  const handleGoogleSignIn = async () => {
    try {
      await signInWithGoogle();
    } catch (err: any) {
      setError(err.message || 'Google sign in failed');
    }
  };

  return (
    <Box>
      <Button variant=”contained” onClick={handleGoogleSignIn}>
        Sign in with Google
      </Button>
    </Box>
  );
};

export default GoogleAuth;

				
			
Authentication Container Component

Create src/components/auth/AuthenticationContainer.tsx :

				
					// AuthenticationContainer.tsx
import React from "react";
import GoogleAuth from "./GoogleAuth";
// import UI elements from material-UI as you need….

const AuthenticationContainer: React.FC = () => {
  return (
    <Box display="flex" justifyContent="center" alignItems="center" minHeight="100vh">
    <Card>
      <CardContent>
        <Typography variant="h5" gutterBottom>
          Sign In
        </Typography>
        <GoogleAuth />
      </CardContent>
    </Card>
  </Box>
  );
};

export default AuthenticationContainer;

				
			
Create Dashboard Component

src/components/Dashboard.tsx :

				
					import React from "react";
import { Button, Typography, Box } from "@mui/material";
import { useAuth } from "../contexts/AuthContext";

const Dashboard: React.FC = () => {
  const { user, signOut } = useAuth();

  return (
    <Box display="flex" flexDirection="column" alignItems="center" gap={2} mt={5}>
      <Typography variant="h5">Welcome, {user?.displayName || "User"}!</Typography>
      <Button variant="outlined" onClick={signOut}>
        Sign Out
      </Button>
    </Box>
  );
};

export default Dashboard;

				
			
Updated Main App Component

Update src/App.tsx :

				
					// App.tsx
import React from "react";
import { CssBaseline, CircularProgress, Box, Typography } from "@mui/material";
import { ThemeProvider, createTheme } from "@mui/material/styles";
import { AuthProvider, useAuth } from "./contexts/AuthContext";
import AuthenticationContainer from "./components/auth/AuthenticationContainer";
import Dashboard from "./components/Dashboard";

const theme = createTheme({ // Customize theme as you need…..});
const LoadingScreen: React.FC = () => (// You can create this for better user experience….);

const AppContent: React.FC = () => {
  const { user, loading } = useAuth();
  if (loading) return <LoadingScreen />;
  return user ? <Dashboard /> : <AuthenticationContainer />;
};

const App: React.FC = () => (
  <ThemeProvider theme={theme}>
    <CssBaseline />
    <AuthProvider>
      <AppContent />
    </AuthProvider>
  </ThemeProvider>
);

export default App;

				
			
Running the Application
				
					npm run dev
				
			

Your application will be available at http://localhost:5173 with a complete authentication system supporting Google sign-in method.

Security Best Practices
  1. Environment Variables : Never commit API keys to version control.
  2. Firebase Security Rules : Implement proper Firestore security rules.
  3. App Check : Enable Firebase App Check for production apps.
  4. Input Validation : Always validate phone numbers and other inputs.
  5. Error Handling : Implement comprehensive error handling and user feedback.
Next Steps

This foundation provides a robust Google authentication system. You can extend it by :

  • Adding user profile management.
  • Implementing protected routes.
  • Adding additional OAuth providers.
  • Integrating with Firestore for user data.

The authentication service and context pattern make it easy to add Facebook and phone authentication, which we’ll cover in the next parts of this series.

Conclusion

This implementation creates a secure production-ready and fully configurable authentication module with various sign-in options. The modular structure allows for easy maintenance and extensibility, and TypeScript gives you the type safety throughout your application. Material UI gives you a professional and accessible user interface that works across all form factors.The authentication workflow accounts for edge cases and user feedback that can be useful in real-world applications.

Loading...

Related Blogs

June 25, 2025
How Lockfiles Ensure Stability and How to Read Them
March 27, 2024
Authentication and Authorization in React
March 28, 2024
Performance Tuning With Liferay
Loading...

Featured Projects Portfolios

November 27, 2023
Government Job Platform _ User-Friendly, Secure, and Scalable
Government Job Platform : User-Friendly, Secure, and Scalable
October 4, 2023
Telemedicine Appointment & Health Record Portal
Telemedicine Appointment & Health Record Portal
June 19, 2024
Music License Management Portal _ Onboarding & Data Integrity
Music License Management Portal : Onboarding & Data Integrity

Digital Solutions for Your Business with IGNEK

4.9

5.0

5.0

5.0

LOGO

Making the world a better place through constructing elegant hierarchies

COMPANY

  • About
  • Career
  • Case Study
  • Blogs

SERVICES

  • Enterprise Portal Development
  • Dedicated Development Team
  • Back-end Development
  • Front-end Development
  • Digital Transformation
  • SaaS Development

HIRE US

  • Liferay
  • Spring Boot
  • ReactJS
  • Healthcare
  • MERN Stack
  • AEM

CONTACT

  • info@insights.ignek.com
  • info@insights.ignek.com
SALES
  • sales@insights.ignek.com
  • (+91) 635 157 6580
CAREER
  • hr@insights.ignek.com
  • (+91) 932 849 5160
  • E 910-912, Ganesh Glory 11, Jagatpur Road, SG Highway, Ahmedabad, Gujarat - 382470

© 2018-2026 IGNEK, Inc. All rights reserved

Linkedin Facebook X-twitter Instagram