📖 Scenario: You are building a simple web app that allows users to reset their password if they forget it. You will use Firebase Authentication to handle the password reset process securely.
🎯 Goal: Create a password reset flow using Firebase Authentication. The user will enter their email, and the app will send a password reset email to that address.
📋 What You'll Learn
Create a Firebase app configuration object with the given API key and project ID
Initialize Firebase Authentication service
Create a function to send a password reset email using Firebase Auth
Add a call to the password reset function with a specific email address
💡 Why This Matters
🌍 Real World
Password reset flows are essential for user account security in web and mobile apps. Firebase Authentication provides a simple way to implement this securely.
💼 Career
Understanding how to implement password reset flows with Firebase is a common task for frontend and backend developers working with cloud services.
Progress0 / 4 steps
1
Create Firebase app configuration
Create a constant called firebaseConfig with these exact properties and values: apiKey: "AIzaSyA-ExampleKey12345", authDomain: "example-app.firebaseapp.com", projectId: "example-app".
Firebase
Hint
Use a JavaScript object with the exact keys and values.
2
Initialize Firebase Authentication
Add these two lines below the firebaseConfig object: import initializeApp from "firebase/app" and import getAuth from "firebase/auth". Then create a constant called app by calling initializeApp(firebaseConfig). Finally, create a constant called auth by calling getAuth(app).
Firebase
Hint
Use ES module import syntax and call the functions with the correct arguments.
3
Create password reset function
Create an async function called sendPasswordReset that takes one parameter email. Inside the function, import sendPasswordResetEmail from "firebase/auth" and call it with auth and email. Use await to wait for the call to complete.
Firebase
Hint
Remember to mark the function as async and use await when calling sendPasswordResetEmail.
4
Call password reset function
Add a call to sendPasswordReset with the exact email string "user@example.com".
Firebase
Hint
Call the function with the exact email string.
Practice
(1/5)
1. What does the Firebase function sendPasswordResetEmail do?
easy
A. Sends an email to the user to reset their password
B. Changes the user's password immediately
C. Deletes the user's account
D. Creates a new user account
Solution
Step 1: Understand the function purpose
The function sendPasswordResetEmail is designed to send an email to the user with a link to reset their password.
Step 2: Differentiate from other actions
This function does not change the password directly or affect the account status; it only initiates the reset process by sending an email.
Final Answer:
Sends an email to the user to reset their password -> Option A
Quick Check:
sendPasswordResetEmail = Sends reset email [OK]
Hint: Remember: sendPasswordResetEmail only sends the reset link [OK]
Common Mistakes:
Thinking it changes the password immediately
Confusing it with account deletion
Assuming it creates a new user
2. Which of the following is the correct syntax to send a password reset email in Firebase using JavaScript?
easy
A. firebase.auth().sendPasswordResetEmail(email)
B. firebase.auth.sendPasswordResetEmail(email)
C. firebase.auth().sendPasswordReset(email)
D. firebase.auth().resetPasswordEmail(email)
Solution
Step 1: Recall the correct Firebase method
The correct method to send a password reset email is sendPasswordResetEmail called on the auth object.
Step 2: Check method call syntax
The auth object is accessed by firebase.auth(), so the full call is firebase.auth().sendPasswordResetEmail(email).
Final Answer:
firebase.auth().sendPasswordResetEmail(email) -> Option A
C. sendPasswordResetEmail is not a Firebase method
D. No internet connection
Solution
Step 1: Check method call syntax
The code calls firebase.auth.sendPasswordResetEmail without parentheses after auth, which is incorrect.
Step 2: Understand correct usage
The correct call is firebase.auth().sendPasswordResetEmail(email) because auth is a function that returns the auth object.
Final Answer:
Missing parentheses after auth() -> Option B
Quick Check:
auth() must be called as a function [OK]
Hint: Always call auth() with parentheses before methods [OK]
Common Mistakes:
Omitting parentheses after auth
Assuming method names are wrong
Ignoring syntax errors
5. You want to implement a password reset flow that shows a success message only if the email was sent, and an error message otherwise. Which code snippet correctly achieves this?
hard
A. firebase.auth().sendPasswordResetEmail(email)
.then(() => alert('Failed to send email'))
.catch(() => alert('Reset email sent'))
B. firebase.auth().sendPasswordResetEmail(email)
.catch(() => alert('Reset email sent'))
.then(() => alert('Failed to send email'))
C. firebase.auth().sendPasswordResetEmail(email)
.then(() => alert('Reset email sent'))
.catch(() => alert('Failed to send email'))
D. firebase.auth().sendPasswordResetEmail(email)
.finally(() => alert('Reset email sent'))
Solution
Step 1: Understand promise handlers order
The then handler runs on success, and catch runs on failure.
Step 2: Match messages to handlers
Success should show 'Reset email sent', failure should show 'Failed to send email'. Only firebase.auth().sendPasswordResetEmail(email)
.then(() => alert('Reset email sent'))
.catch(() => alert('Failed to send email')) matches this logic correctly.
Final Answer:
firebase.auth().sendPasswordResetEmail(email)
.then(() => alert('Reset email sent'))
.catch(() => alert('Failed to send email')) -> Option C
Quick Check:
then() = success, catch() = error [OK]
Hint: Use then() for success, catch() for errors [OK]
Common Mistakes:
Swapping then and catch handlers
Using finally for success message
Showing error message on success
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.