Revise email-users example to handle multiple function executions for a single user
See original GitHub issueI’m using the code from the sample here: https://github.com/firebase/functions-samples/tree/master/quickstarts/email-users
onCreate is sometimes triggered multiple times for the same user. Most of the time it is triggered once, but sometimes it is triggered two times or even 7 times (which happened yesterday).
exports.sendWelcomeEmail = functions.auth.user().onCreate(event => {
No errors in the log, just the normal debug statements and the text output from console.log('New welcome email sent to:', email);
If I choose “View all from this execution”, all 7 are shown, so they come from the same execution.
7 emails are also sent, so it’s not just the debug output.
Only 1 account is created.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Send email using Lambda and Amazon SES - AWS
To send email from a Lambda function using Amazon SES, do the following: 1. Create an AWS Identity and Access Management (IAM) policy...
Read more >Outlook email template: 10 quick ways to create and use
In-depth tutorial: How to create and use Outlook email templates ... shortcuts that allow performing multiple actions with a single command.
Read more >Azure Functions best practices | Microsoft Learn
You can use the following ARM template examples to help correctly configure ... such as managing triggers and logging function executions.
Read more >Understand How Metadata Works in User Profiles
Use Rules. Rules are JavaScript functions executed as part of the Auth0 authentication process (prior to authorization). Using rules, you can read, create ......
Read more >Managing Users
To manage users, you must have one of the following roles: User Manager; User Administrator; Circulation Desk Manager; Circulation Desk ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
According to Firebase engineer @laurenzlong, multiple executions is expected behavior and functions should be idempotent. Sending an email is not idempotent.
Can we please have this issue re-opened? It’d be helpful to have the example show how to ensure an email doesn’t get sent two or more times.
Thanks.
For anyone having a similar issue I found this documentation here for Google Cloud Functions which explains http functions are called at most once and background functions are called at least once.
The solution I found is to just have a standalone http function which can be called by a POST request with the data you want to handle.
Only consideration with this method is CORS, which will send two requests to the function unless you’re careful with the content of your POST request. More information is available here.
I appreciate it’s not that elegant but due to the nature of Cloud Functions I can’t see another way to resolve this.
I’m a newbie here so apologies if any of this is unhelpful!