How to use Firebase RealTime Database for Auth
Mon 10 2024
Written By - Aman Kumar Verma
#What is Firebase?
Firebase Realtime Database is a cloud-hosted NoSQL database that allows Developers to
store and sync data in real time across all of their users' devices.
Firebase is used by a variety of companies, including Airbnb, Coca-Cola and Pinterest.
When Any one using Firebase as their database need they don't have to care about the
backend
the backend is provided by Firebase.
#How to use Firebase for Auth?
Before going on the Auth, use must have to know what is Auth . Auth or Authentication is
the process by which a person or system verifies that they are who they say they are
In simple way whenever you try to purchase any things through e-commerce website eg
Amazon, Myntra
you first have to signIn or have to Create an Account this is an example of real world
Auth based scanerio.
- First you have to Create an Account on Firebase.
- After that you will transfer to Dashboard or if you not redirected to Dashboard then
find go to console option.
- Then Search for add project Option and fill all details of your application or
website.
- Then click on Project Overview --> Project Settings which is Present of left side
panel.
- Scroll Down and copy your Configuration code and paste in your website.
- On left side panel their is an Authentication option click on it and choose auth
provider for this case we will choose google for our auth provider.
- After Completing these process Know move to Integration in web topics.
#Integration in Web
- https://cdnjs.cloudflare.com/ajax/libs/firebase/10.12.2/firebase-app-compat.min.js"
integrity="sha512-7VG+AGc4sddCVxEvzT+Z8fjIWq1Hrnnhp2swwiXXNnKT1cYB4vCyHPFO6JhQjQQ/oa26fNK0mpFg4vTvxBS3sw=="
crossorigin="anonymous" referrerpolicy="no-referrer">
- https://cdnjs.cloudflare.com/ajax/libs/firebase/10.12.2/firebase-auth-compat.min.js"
integrity="sha512-KjIesTv/W/AhBjwjMjEzMZgIKwfzBnvRhc/UCHWukIHJvpxTN8/vvYHX7cwQSc4OcwYAjLd6cAWbAuFqR5vZCA=="
crossorigin="anonymous" referrerpolicy="no-referrer">
- https://cdnjs.cloudflare.com/ajax/libs/firebase/10.12.2/firebase-firestore-compat.min.js"
integrity="sha512-tR8LqQ63s+NuKDdtuehjKG13GGxKoTWXsF7qhgdc3l6vul6Wo8N7qnHTCuOJmQ8LdUC+7HphupqtMXysWZN5vg=="
crossorigin="anonymous" referrerpolicy="no-referrer"
copy one by one these CDN links and paste in the script tag
const app = firebase.initializeApp(firebaseConfig)
var provider = new firebase.auth.GoogleAuthProvider();
firebase.auth()
.signInWithPopup(provider)
.then((result) => {
var credential = result.credential;
var token = credential.accessToken;
var user = result.user;
}).catch((error) => {
var errorCode = error.code;
var errorMessage = error.message;
var email = error.email;
var credential = error.credential;
});