Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • React Tutorial
  • React Exercise
  • React Basic Concepts
  • React Components
  • React Props
  • React Hooks
  • React Router
  • React Advanced
  • React Examples
  • React Interview Questions
  • React Projects
  • Next.js Tutorial
  • React Bootstrap
  • React Material UI
  • React Ant Design
  • React Desktop
  • React Rebass
  • React Blueprint
  • JavaScript
  • Web Technology
Open In App
Next Article:
Twitter Authentication with Firebase
Next article icon

How to authenticate firebase with GitHub in ReactJS ?

Last Updated : 26 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

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              &nbsp;&nbsp;              {                 auth.currentUser.email             }             &nbsp;&nbsp;              <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:


Next Article
Twitter Authentication with Firebase
author
iamabhishekkalra
Improve
Article Tags :
  • Web Technologies
  • ReactJS
  • Firebase
  • GitHub

Similar Reads

  • How to authenticate with google using firebase in React ?
    The following approach covers how to authenticate with Google using firebase in react. We have used firebase module to achieve so. Creating React Application And Installing Module: Step 1: Create a React myapp using the following command: npx create-react-app myappStep 2: After creating your project
    3 min read
  • How to authenticate phone number using firebase in ReactJS ?
    User authentication is a critical aspect of many web applications, and phone number authentication has become increasingly popular for its convenience and security. Firebase, a powerful platform developed by Google, offers various authentication methods, including phone number authentication. Prereq
    3 min read
  • GitHub Authentication with Firebase
    GitHub Authentication in Firebase allows users to sign in to our web application using their GitHub credentials. This integration uses GitHub's OAuth authentication system which provides a secure and convenient way for users to access your app. By integrating GitHub authentication, we can enhance us
    5 min read
  • How to get current date and time in firebase using ReactJS ?
    This article provides a detailed walkthrough on obtaining the current date and time in a Firebase environment using ReactJS. Readers will gain insights into the implementation process, enabling date and time functionalities into their React projects powered by Firebase. Prerequisites:Node JS or NPMR
    2 min read
  • Twitter Authentication with Firebase
    Twitter Authentication allows users to sign in to applications using their Twitter credentials, providing a simple and familiar sign-in experience. By integrating Twitter Authentication with Firebase, developers can simplify the authentication process and enhance the user experience. In this article
    5 min read
  • Google SignIn using Firebase Authentication in ReactJS
    Firebase simplifies mobile and web app development by offering pre-built features like user authentication (email/password, Google Sign-In, etc.) without the need to build complex backends. This saves time and resources for developers.In this article, we will discuss about the Google Sign-In feature
    4 min read
  • How to Authenticate with Google using Firebase in React Native Application ?
    In this article, we will discuss how can we authenticate with Google using Firebase in React Native. Creating React Application And Installing ModuleCreate a React app using the following command: npx react-native@latest init AwesomeProjectProject StructureNow install required npm packages: npm i @r
    2 min read
  • How to Authenticate Git Push with Github Using a Token?
    Git is a powerful version control system used by developers to track changes in their codebase. GitHub, a platform built around Git, allows developers to collaborate on projects and manage repositories. For years, developers have been using their GitHub username and password to authenticate Git oper
    4 min read
  • Google Authentication with Firebase
    Google Authentication, a method of verifying user identities using Google credentials, provides a seamless and secure way for users to sign in to applications. With the help of Firebase, developers can integrate Google Authentication into their apps and allowing users to sign in with their existing
    5 min read
  • How to Use Authentication Console in Firebase?
    Almost all apps need to have some permission system in place. In some circumstances, checking a username/password pair against our Users table is sufficient. Still, frequently, we require a more detailed permissions model to grant specific users access to particular resources while preventing them f
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences