Why should Authentication trigger functions be used carefully?
Because they run automatically and can affect your database or other services, mistakes can cause data loss or errors. Always test and handle errors properly.
Click to reveal answer
Which Firebase Authentication trigger runs when a user signs up?
AonCreate
BonDelete
ConUpdate
DonLogin
✗ Incorrect
The onCreate trigger runs automatically when a new user account is created.
What does the onDelete Authentication trigger do?
ARuns when a user logs in
BRuns when a user updates their profile
CRuns when a user account is deleted
DRuns when a user resets password
✗ Incorrect
The onDelete trigger runs automatically when a user account is deleted.
Why use Authentication trigger functions in Firebase?
ATo automatically manage user data on sign up or deletion
BTo speed up user login
CTo change user passwords
DTo send emails manually
✗ Incorrect
They help keep user data in sync by running code automatically on user creation or deletion.
Which Firebase service is commonly used inside Authentication trigger functions to store user data?
AFirebase Hosting
BCloud Firestore
CFirebase Analytics
DFirebase Storage
✗ Incorrect
Cloud Firestore is often used to save or clean up user data triggered by Authentication events.
What should you always do when writing Authentication trigger functions?
AIgnore errors to keep functions fast
BUse them only for sending emails
CRun them manually only
DTest carefully and handle errors
✗ Incorrect
Testing and error handling prevent data loss and unexpected problems.
Explain what Authentication trigger functions are and how they work in Firebase.
Think about what happens when a user signs up or deletes their account.
You got /4 concepts.
Describe a simple use case where you would use an onCreate Authentication trigger function.
Imagine you want to save new user info right after they join.
You got /3 concepts.
Practice
(1/5)
1. What does the Firebase Authentication trigger function onCreate do?
easy
A. It sends a password reset email.
B. It deletes a user from the database.
C. It runs automatically when a new user signs up.
D. It updates user profile information.
Solution
Step 1: Understand the purpose of onCreate
The onCreate trigger runs when a new user account is created in Firebase Authentication.
Step 2: Match the trigger to the correct action
Since it runs on new user sign-up, it does not delete users or send emails directly.
Final Answer:
It runs automatically when a new user signs up. -> Option C
Quick Check:
onCreate = New user signup trigger [OK]
Hint: Remember: onCreate = new user signup trigger [OK]
Common Mistakes:
Confusing onCreate with onDelete trigger
Thinking onCreate sends emails automatically
Assuming onCreate updates user data
2. Which of the following is the correct syntax to define a Firebase Authentication trigger function for user deletion in Node.js?
easy
A. functions.auth.user().onCreate((user) => { /* code */ });
B. exports.userDeleted = functions.auth.user().onDelete((user) => { /* code */ });
C. exports.userDeleted = functions.auth.user().onRemove((user) => { /* code */ });
D. functions.auth.user().delete((user) => { /* code */ });
Solution
Step 1: Identify the correct trigger for user deletion
The correct trigger for user deletion is onDelete attached to functions.auth.user().
Step 2: Check the syntax for exporting the function
The function should be exported using exports.functionName = ... syntax.
B. Incorrect trigger function; should use onCreate instead of onDelete.
C. Missing return statement for the database operation.
D. The user parameter should be destructured as { uid }.
Solution
Step 1: Check for admin SDK initialization
The code uses admin.database() but does not show admin being imported or initialized, which causes runtime errors.
Step 2: Verify other parts of the code
The trigger and user parameter usage are correct; missing return is not mandatory but recommended.
Final Answer:
admin is not initialized or imported. -> Option A
Quick Check:
admin SDK must be initialized before use [OK]
Hint: Always import and initialize admin SDK before database calls [OK]
Common Mistakes:
Confusing onDelete with onCreate trigger
Ignoring admin SDK initialization
Thinking return statement is mandatory
5. You want to send a welcome email only to users who sign up with an email ending in @example.com. Which code snippet correctly implements this using Firebase Authentication trigger functions?
hard
A. exports.sendWelcomeEmail = functions.auth.user().onCreate((user) => {
if (user.email.endsWith('@example.com')) {
sendEmail(user.email);
}
});
B. exports.sendWelcomeEmail = functions.auth.user().onDelete((user) => {
if (user.email.includes('@example.com')) {
sendEmail(user.email);
}
});
C. exports.sendWelcomeEmail = functions.auth.user().onCreate((user) => {
if (user.email === '@example.com') {
sendEmail(user.email);
}
});
D. exports.sendWelcomeEmail = functions.auth.user().onCreate((user) => {
if (user.email.indexOf('@example.com') === 0) {
sendEmail(user.email);
}
});
Solution
Step 1: Choose the correct trigger for new user sign-up
Use onCreate to run code when a user signs up, not onDelete.
Step 2: Check the email condition for domain matching
Use endsWith('@example.com') to check if the email ends with the domain. Using includes or equality check is incorrect here.
Final Answer:
exports.sendWelcomeEmail = functions.auth.user().onCreate((user) => {
if (user.email.endsWith('@example.com')) {
sendEmail(user.email);
}
}); -> Option A
Quick Check:
Use onCreate + endsWith() for domain check [OK]
Hint: Use onCreate and endsWith('@domain.com') to filter emails [OK]
Common Mistakes:
Using onDelete instead of onCreate
Checking email equality instead of endsWith
Using indexOf === 0 instead of endsWith
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.