Bird
Raised Fist0
Firebasecloud~20 mins

Authentication trigger functions in Firebase - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Authentication Trigger Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate
2:00remaining
What is the output of this Firebase Authentication trigger function?
Consider this Firebase Cloud Function that triggers when a user is created. What will be logged when a new user with email 'user@example.com' is created?
Firebase
exports.userCreated = functions.auth.user().onCreate((user) => {
  console.log(`New user created: ${user.email}`);
  return null;
});
ANew user created: user@example.com
BNew user created: undefined
CError: user.email is not defined
DNo output is logged
Attempts:
2 left
💡 Hint
The user object passed to the trigger contains the user's email property.
🧠 Conceptual
intermediate
1:30remaining
Which Firebase Authentication trigger runs when a user deletes their account?
Firebase Authentication provides triggers for user lifecycle events. Which trigger function runs when a user deletes their account?
Afunctions.auth.user().onDestroy()
Bfunctions.auth.user().onRemove()
Cfunctions.auth.user().onDelete()
Dfunctions.auth.user().onExpire()
Attempts:
2 left
💡 Hint
The trigger name includes 'Delete' for account deletion.
📝 Syntax
advanced
2:30remaining
Identify the syntax error in this Firebase Authentication trigger function
Which option contains the correct syntax for a Firebase Authentication onCreate trigger function?
Firebase
exports.newUser = functions.auth.user().onCreate((user) => {
  console.log('User created:', user.uid);
  return null;
});
A
exports.newUser = functions.auth.user().onCreate((user) => {
  console.log('User created:', user.uid);
  return null;
}
B
exports.newUser = functions.auth.user().onCreate((user) => {
  console.log('User created:', user.uid)
  return null;
});
C
exports.newUser = functions.auth.user().onCreate(user => {
  console.log('User created:', user.uid);
  return null;
});
D
exports.newUser = functions.auth.user().onCreate((user) => {
  console.log('User created:', user.uid);
  return null;
});
Attempts:
2 left
💡 Hint
Check for missing semicolons and balanced brackets.
❓ optimization
advanced
2:00remaining
How to optimize a Firebase Authentication onCreate trigger to minimize cold start time?
You want your Firebase Authentication onCreate trigger to run quickly when a user signs up. Which practice helps reduce cold start delays?
AUse global imports and initialize heavy libraries outside the trigger function
BImport only necessary modules inside the trigger function, not globally
CWrite all code inside the trigger function without external imports
DAvoid using async/await in the trigger function
Attempts:
2 left
💡 Hint
Cold start is affected by how much code loads before the function runs.
🔧 Debug
expert
3:00remaining
Why does this Firebase Authentication onDelete trigger fail to run?
Given this code, why does the onDelete trigger not execute when a user deletes their account? exports.userDeleted = functions.auth.user().onDelete((user) => { console.log('User deleted:', user.uid); return null; });
AThe user parameter is undefined in onDelete triggers
BThe function is not deployed to Firebase after code changes
CThe trigger should be onRemove, not onDelete
DFirebase Authentication does not support onDelete triggers
Attempts:
2 left
💡 Hint
Check if the function is active in your Firebase project.

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

  1. Step 1: Understand the purpose of onCreate

    The onCreate trigger runs when a new user account is created in Firebase Authentication.
  2. 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.
  3. Final Answer:

    It runs automatically when a new user signs up. -> Option C
  4. 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

  1. Step 1: Identify the correct trigger for user deletion

    The correct trigger for user deletion is onDelete attached to functions.auth.user().
  2. Step 2: Check the syntax for exporting the function

    The function should be exported using exports.functionName = ... syntax.
  3. Final Answer:

    exports.userDeleted = functions.auth.user().onDelete((user) => { /* code */ }); -> Option B
  4. Quick Check:

    onDelete trigger syntax = exports.userDeleted = functions.auth.user().onDelete((user) => { /* code */ }); [OK]
Hint: Use exports.functionName = functions.auth.user().onDelete(...) [OK]
Common Mistakes:
  • Using onCreate instead of onDelete for deletion
  • Using non-existent onRemove trigger
  • Not exporting the function properly
3. Given the following Firebase Authentication trigger function, what will be logged when a user signs up?
exports.welcomeUser = functions.auth.user().onCreate((user) => {
  console.log(`Welcome, ${user.email}!`);
});
medium
A. Welcome, undefined!
B. Welcome, user.email!
C. No output, function does not run on sign-up.
D. Welcome, user@example.com!

Solution

  1. Step 1: Understand the onCreate trigger behavior

    The function runs automatically when a new user signs up, receiving the user object with an email property.
  2. Step 2: Analyze the console.log statement

    The template string inserts the user's email, so it logs "Welcome, user@example.com!" if the user's email is user@example.com.
  3. Final Answer:

    Welcome, user@example.com! -> Option D
  4. Quick Check:

    onCreate logs user email correctly [OK]
Hint: onCreate passes user object with email property [OK]
Common Mistakes:
  • Assuming user.email is undefined
  • Thinking function does not run on sign-up
  • Misreading template string syntax
4. Identify the error in this Firebase Authentication trigger function code:
exports.deleteUserData = functions.auth.user().onDelete(user => {
  const uid = user.uid;
  admin.database().ref(`/users/${uid}`).remove();
});
medium
A. admin is not initialized or imported.
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

  1. 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.
  2. Step 2: Verify other parts of the code

    The trigger and user parameter usage are correct; missing return is not mandatory but recommended.
  3. Final Answer:

    admin is not initialized or imported. -> Option A
  4. 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

  1. Step 1: Choose the correct trigger for new user sign-up

    Use onCreate to run code when a user signs up, not onDelete.
  2. 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.
  3. Final Answer:

    exports.sendWelcomeEmail = functions.auth.user().onCreate((user) => { if (user.email.endsWith('@example.com')) { sendEmail(user.email); } }); -> Option A
  4. 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 unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard