📖 Scenario: You are building a simple web app that allows users to sign in using their Google account. This helps users log in quickly without creating a new password.
🎯 Goal: Create a Firebase project setup that enables Google sign-in authentication and implement the sign-in logic in your web app.
📋 What You'll Learn
Initialize Firebase in your project with the given config
Create a Firebase Auth instance
Set up GoogleAuthProvider for Google sign-in
Implement a function to trigger Google sign-in popup
💡 Why This Matters
🌍 Real World
Google sign-in is a common way to let users quickly log into web apps without creating new passwords, improving user experience and security.
💼 Career
Understanding how to integrate third-party authentication providers like Google with Firebase is a valuable skill for frontend and full-stack developers working on modern web applications.
Progress0 / 4 steps
1
Initialize Firebase
Create a constant called firebaseConfig with the exact keys and values: apiKey: "AIzaSyExampleKey12345", authDomain: "your-app.firebaseapp.com", projectId: "your-app", storageBucket: "your-app.appspot.com", messagingSenderId: "1234567890", appId: "1:1234567890:web:abcdef123456". Then initialize Firebase with initializeApp(firebaseConfig) and assign it to a constant called app.
Firebase
Hint
Use const firebaseConfig = { ... } with the exact keys and values. Then call initializeApp(firebaseConfig) and assign it to app.
2
Create Firebase Auth Instance
Create a constant called auth and assign it the result of calling getAuth(app).
Firebase
Hint
Use const auth = getAuth(app); to create the auth instance.
3
Set Up GoogleAuthProvider
Create a constant called provider and assign it a new instance of GoogleAuthProvider().
Firebase
Hint
Use const provider = new GoogleAuthProvider(); to create the provider.
4
Implement Google Sign-In Function
Create an async function called signInWithGoogle that calls signInWithPopup(auth, provider) and awaits its result.
Firebase
Hint
Define async function signInWithGoogle() and inside it call await signInWithPopup(auth, provider);.
Practice
(1/5)
1. What is the main purpose of using Google sign-in with Firebase Authentication?
easy
A. To store user data in Google Drive
B. To let users log in easily using their Google accounts
C. To send emails through Gmail automatically
D. To create Google Cloud virtual machines
Solution
Step 1: Understand Firebase Authentication
Firebase Authentication helps users sign in securely to apps.
Step 2: Identify Google sign-in role
Google sign-in allows users to log in using their Google accounts easily.
Final Answer:
To let users log in easily using their Google accounts -> Option B
Quick Check:
Google sign-in = Easy user login [OK]
Hint: Google sign-in means easy login with Google accounts [OK]
Common Mistakes:
Confusing sign-in with data storage
Thinking it sends emails automatically
Assuming it manages cloud machines
2. Which Firebase Authentication code snippet correctly initializes Google sign-in in JavaScript?
easy
A. const provider = new firebase.auth.TwitterAuthProvider();
B. const provider = new firebase.auth.EmailAuthProvider();
C. const provider = new firebase.auth.FacebookAuthProvider();
D. const provider = new firebase.auth.GoogleAuthProvider();
Solution
Step 1: Identify correct provider for Google sign-in
Google sign-in uses GoogleAuthProvider in Firebase Authentication.
Step 2: Match code snippet
The snippet with new firebase.auth.GoogleAuthProvider() is correct.
Final Answer:
const provider = new firebase.auth.GoogleAuthProvider(); -> Option D
Quick Check:
GoogleAuthProvider = Google sign-in [OK]
Hint: Google sign-in uses GoogleAuthProvider class [OK]
Common Mistakes:
Using EmailAuthProvider for Google sign-in
Confusing with Twitter or Facebook providers
Missing 'new' keyword in initialization
3. Given this JavaScript code snippet for Google sign-in, what will be logged if the user successfully signs in?