How to authenticate firebase with GitHub in ReactJS ?
Last Updated :
26 Jul, 2024
The following approach covers how to authenticate firebase with GitHub in react. We have used the firebase module to achieve so.
Creating React Application And Installing Module:
Step 1: Create a React app using the following command:
npx create-react-app gfgapp
Step 2: After creating your project folder i.e. gfgapp, move to it using the following command:
cd gfgapp
Project structure: Our project structure will look like this.

Step 3: After creating the ReactJS application, Install the firebase module using the following command:
npm install [email protected] --save
Step 4: Go to your firebase dashboard and create a new project and copy your credentials.
const firebaseConfig = {
apiKey: "your api key",
authDomain: "your credentials",
projectId: "your credentials",
storageBucket: "your credentials",
messagingSenderId: "your credentials",
appId: "your credentials"
};
Step 5: Initialize the Firebase into your project by creating Firebase.js file with the following code.
Firebase.js
import firebase from 'firebase';
const firebaseConfig = {
// Your Credentials
};
firebase.initializeApp(firebaseConfig);
var auth = firebase.auth();
var provider = new firebase.auth.GithubAuthProvider();
export {auth , provider};
Step 6: Register your app as a developer application on GitHub and get your app's OAuth 2.0 Client ID and Client Secret.

For Authorization callback URL go to your authentication section and click on Github sign-in method. After that copy the callback URL.

Step 7: Now Enable the Github sign-in method by entering your Client ID and Client Secret.Â

Step 8: Now install the npm package i.e. react-firebase-hooks using the following command.
npm i react-firebase-hooks
This package helps us to listen to the current state of the user.
Step 9: Create two files i.e. login.js and main.js with the following code.
login.js
import {auth , provider} from './firebase';
const Login = ()=>{
// SignIn with GitHub
const submit = ()=>{
auth.signInWithPopup(provider).catch(alert);
}
return (
<div>
<center>
<button onClick={submit}>
SignIn with Github
</button>
</center>
</div>
)
}
export default Login;
main.js
import {auth} from './firebase';
const Main = ()=>{
const logout = ()=>{
auth.signOut();
}
return(
<div>
Welcome
{
auth.currentUser.email
}
<button onClick={logout}>
Logout
</button>
</div>
)
}
export default Main;
Step 10: Finally Import all required files in App.js file as shown below.
App.js
import './App.css';
import Login from './login';
import {auth} from './firebase';
import Main from './main';
import {useAuthState} from 'react-firebase-hooks/auth';
function App() {
const [user] = useAuthState(auth);
return (
user ? <Main/> : <Login/>
);
}
export default App;
Step to Run Application: Run the application using the following command from the root directory of the project:
npm start
Output: Now open your browser and go to http://localhost:3000/, you will see the following output:
Similar Reads
React Interview Questions and Answers React is an efficient, flexible, and open-source JavaScript library that allows developers to create simple, fast, and scalable web applications. Jordan Walke, a software engineer who was working for Facebook, created React. Developers with a JavaScript background can easily develop web applications
15+ min read
React Tutorial React is a powerful JavaScript library for building fast, scalable front-end applications. Created by Facebook, it's known for its component-based structure, single-page applications (SPAs), and virtual DOM,enabling efficient UI updates and a seamless user experience.Note: The latest stable version
7 min read
90+ React Projects with Source Code [2025] React, managed by Facebook and a vibrant community of developers and companies, is a JavaScript library designed to craft dynamic user interfaces. It empowers developers with concepts like React web apps, components, props, states, and component lifecycles. With a primary focus on building single-pa
12 min read
Frontend Developer Interview Questions and Answers Frontend development is an important part of web applications, and it is used to build dynamic and user-friendly web applications with an interactive user interface (UI). Many companies are hiring skilled Frontend developers with expertise in HTML, CSS, JavaScript, and modern frameworks and librarie
15+ min read
React Introduction ReactJS is a component-based JavaScript library used to build dynamic and interactive user interfaces. It simplifies the creation of single-page applications (SPAs) with a focus on performance and maintainability.It is developed and maintained by Facebook.The latest version of React is React 19.Uses
8 min read
Git Tutorial Git is an essential tool for developers, enabling them to manage and track project changes. Whether you're working on a solo project or collaborating with a team, Git keeps everything organized and under control. This Git Tutorial, from beginner to advanced, will give you a complete understanding of
12 min read
Git Cheat Sheet Git Cheat Sheet is a comprehensive quick guide for learning Git concepts, from very basic to advanced levels. By this Git Cheat Sheet, our aim is to provide a handy reference tool for both beginners and experienced developers/DevOps engineers. This Git Cheat Sheet not only makes it easier for newcom
10 min read
React Hooks ReactJS Hooks are one of the most powerful features of React, introduced in version 16.8. They allow developers to use state and other React features without writing a class component. Hooks simplify the code, make it more readable, and offer a more functional approach to React development. With hoo
10 min read
React JSX JSX stands for JavaScript XML, and it is a special syntax used in React to simplify building user interfaces. JSX allows you to write HTML-like code directly inside JavaScript, enabling you to create UI components more efficiently. Although JSX looks like regular HTML, itâs actually a syntax extensi
6 min read
React Router React Router is a library for handling routing and navigation in React JS Applications. It allows you to create dynamic routes, providing a seamless user experience by mapping various URLs to components. It enables navigation in a single-page application (SPA) without refreshing the entire page.This
6 min read