@@ -373,6 +373,50 @@ void main(List<String> args) {
373373 },
374374 );
375375
376+ // Before email sent - runs before password reset or sign-in emails
377+ // NOTE: The Auth emulator only supports beforeCreate and beforeSignIn.
378+ // This function is included for manifest snapshot testing but cannot be
379+ // tested with the emulator.
380+ firebase.identity.beforeEmailSent (
381+ (AuthBlockingEvent event) async {
382+ print ('Before email sent:' );
383+ print (' Email Type: ${event .emailType ?.value }' );
384+ print (' IP Address: ${event .ipAddress }' );
385+
386+ // Example: Rate limit password reset emails
387+ // In production, you'd check against a database
388+ if (event.emailType == EmailType .passwordReset) {
389+ // Could return BeforeEmailResponse(
390+ // recaptchaActionOverride: RecaptchaActionOptions.block,
391+ // ) to block suspicious requests
392+ }
393+
394+ return null ;
395+ },
396+ );
397+
398+ // Before SMS sent - runs before MFA or sign-in SMS messages
399+ // NOTE: The Auth emulator only supports beforeCreate and beforeSignIn.
400+ // This function is included for manifest snapshot testing but cannot be
401+ // tested with the emulator.
402+ firebase.identity.beforeSmsSent (
403+ (AuthBlockingEvent event) async {
404+ print ('Before SMS sent:' );
405+ print (' SMS Type: ${event .smsType ?.value }' );
406+ print (' Phone: ${event .additionalUserInfo ?.phoneNumber }' );
407+
408+ // Example: Block SMS to certain country codes
409+ final phone = event.additionalUserInfo? .phoneNumber;
410+ if (phone != null && phone.startsWith ('+1900' )) {
411+ return const BeforeSmsResponse (
412+ recaptchaActionOverride: RecaptchaActionOptions .block,
413+ );
414+ }
415+
416+ return null ;
417+ },
418+ );
419+
376420 print ('Functions registered successfully!' );
377421 });
378422}
0 commit comments