This quickstart demonstrates how to setup an Auth triggered Cloud Function using the Firebase SDK for Cloud Functions and Resend.
We'll deploy 2nd gen Auth triggered functions that send a welcome email when a new user signs up and a goodbye email when user accounts are deleted.
- Read more about Cloud Functions for Firebase
- Read more about the Firebase Local Emulator Suite
- Connect Cloud Functions to the Emulator
The functions are organized into separate files for clean, self-contained documentation snippets and modular code:
- functions/sendWelcomeEmail.js:
sendWelcomeEmailtriggers on all user creations across the project (default behavior). - functions/sendByeEmail.js:
sendByeEmailtriggers when any user account is deleted. - functions/tenants.js: Multi-tenancy examples:
sendWelcomeEmailToTenant: Scoped to users in a specific Identity Platform tenant usingtenantId: "my-tenant-id".sendWelcomeEmailNoTenant: Triggers only for users not associated with any tenant usingtenantId: IS_NOT_TENANT.
- functions/utils/myEmailService.js: Configures the Resend client, defines the
EMAIL_API_KEYsecret, and provides thesendEmail,sendWelcomeEmail, andsendGoodbyeEmailhelpers. - functions/index.js: Entry point re-exporting all function triggers.
Sending emails is performed using Resend. The dependencies are listed in functions/package.json.
- Clone or download this repo and navigate to
Node/quickstarts/email-users:cd Node/quickstarts/email-users - Install Cloud Functions dependencies:
cd functions && pnpm install && cd ..
- Set your Resend API key for local development in
functions/.secret.local(the emulator reads secret values from that file):EMAIL_API_KEY="re_123456789"You can obtain a free API key from Resend.
The Firebase Local Emulator Suite lets you test Auth triggers and create/delete users directly in the Emulator UI without deploying to a live project.
- Start the emulators:
firebase emulators:start
- Open the Emulator Suite UI in your browser at http://localhost:4000 (or the port printed in your terminal).
- Navigate to the Authentication tab.
- Trigger
sendWelcomeEmail: Click Add user, enter an email address and display name, and click Save. - Trigger
sendByeEmail: Select the user you just created and click Delete user. - View the logs in the Logs tab of the Emulator Suite UI or in your terminal to see the functions execute:
New welcome email sent to: user@example.com
Account deletion confirmation email sent to: user@example.com
To deploy the functions to a live Firebase project:
- Configure your Firebase project:
firebase use --add
- Set your Resend API key as a Cloud Secret:
firebase functions:secrets:set EMAIL_API_KEY
- Deploy the functions:
firebase deploy --only functions
We'd love that you contribute to the project. Before doing so please read our Contributor guide.
© Google, 2026. Licensed under an Apache-2 license.