Skip to content

Add beforeSendEmail and beforeSendSms blocking functions samples#1253

Open
macastelaz wants to merge 1 commit intofirebase:mainfrom
macastelaz:add-before-send-samples
Open

Add beforeSendEmail and beforeSendSms blocking functions samples#1253
macastelaz wants to merge 1 commit intofirebase:mainfrom
macastelaz:add-before-send-samples

Conversation

@macastelaz
Copy link
Copy Markdown

Supplement samples in Node and Python to include examples of beforeSendEmail and beforeSendSms

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces new Firebase Auth Blocking functions for both Node.js and Python quickstarts. It adds beforeEmailSent and beforeSmsSent triggers to block email sending to non-acme.com domains and SMS sending to non-US phone numbers. The review comments suggest minor readability improvements in the Node.js functions by explicitly checking for the existence of user.email and user.phoneNumber before calling string methods, even though optional chaining provides functional safety.


// [START v2emailHttpsError]
// Only users of a specific domain can receive emails.
if (!user?.email?.includes("@acme.com")) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using optional chaining with includes on a potentially undefined email property is safe, but for better readability and explicit null checking, consider checking if the email exists before calling includes.

Suggested change
if (!user?.email?.includes("@acme.com")) {
if (user?.email && !user.email.includes("@acme.com")) {


// [START v2smsHttpsError]
// Only users of a specific region can receive SMS.
if (!user?.phoneNumber?.startsWith("+1")) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the email check, explicitly validating the existence of phoneNumber before calling startsWith improves code clarity.

Suggested change
if (!user?.phoneNumber?.startsWith("+1")) {
if (user?.phoneNumber && !user.phoneNumber.startsWith("+1")) {

@macastelaz macastelaz force-pushed the add-before-send-samples branch 2 times, most recently from b71c7de to d41d3a8 Compare April 1, 2026 00:56
@macastelaz macastelaz force-pushed the add-before-send-samples branch from d41d3a8 to b87ceec Compare April 1, 2026 01:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant