Stop the default multi-factor enrolment notification email template in firebase (Flutter)

  Kiến thức lập trình

I am in the process of customizing all of the auth flows in firebase using my own backend emailing service. I have been successful customizing all of them and have a custom multi-factor enrolment notification ready and working.

My question is, how can I stop the default multi-factor enrolment notification from triggering whenever I enrol a new multi-factor?

`
Future enrollSms2fa(
String phoneNumber,
BuildContext context,
final VoidCallback onSuccess,
final VoidCallback stopProcessing,
final void Function(String) onError,) async {
final session = await _firebaseAuth.currentUser?.multiFactor.getSession();
await firebaseAuth.verifyPhoneNumber(
multiFactorSession: session,
phoneNumber: phoneNumber,
verificationCompleted: (
) {},
verificationFailed: (e) {
onError(‘${e.message}’);
},
codeSent: (String verificationId, int? resendToken) async {
final smsCode = await getSmsCodeFromUser(context);

    if (smsCode != null) {
      final credential = PhoneAuthProvider.credential(
        verificationId: verificationId,
        smsCode: smsCode,
      );

      try {
        await _firebaseAuth.currentUser?.multiFactor.enroll(
          PhoneMultiFactorGenerator.getAssertion(
            credential,
          ),
          displayName: phoneNumber,
        );
        onSuccess();
      } on FirebaseAuthException catch (e) {
        onError('${e.message}');
        if (context.mounted) {
          Navigator.of(context).pop();
        }
        stopProcessing();
        String? errorMessage;
        if ('${e.message}'.contains("Firebase:")) {
          errorMessage = '${e.message}'.split('Firebase: ')[1];
        }
        onError(errorMessage!);
      } catch (e) {
        onError('$e');
        if (context.mounted) {
          Navigator.of(context).pop();
        }
        stopProcessing();
        onError('$e');
      }
    }
  },
  codeAutoRetrievalTimeout: (e) {
    onError(e.toString());
  },
);

}
`

Here is the code I’m running to enrol a sms 2-fa:

I don’t want to send the default email as I have my own custom one I want to use. And If I can’t disable the default one the user will receive two different emails.

I’ve tried reading through all the docs but can’t seem to find anything relevant to enrolling and skipping the email notification.

New contributor

Jared Stevenson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT