Search code examples
firebasefirebase-authenticationfirebase-extensions

Custom Firebase Email Verification Template and Action Handler


I would like to customize the email template (using the Trigger Email extension templates) to send verification links to users.

I understand it is not possible to change the template from the Firebase console as it prevents spam.

I am aware of the ability to customize action email handlers (The page that the user lands on when the link in verification email is clicked), as well as the ability to update the auth user's emailVerified property manually.

Is there also a way to generate the verification link that firebase would have used? One with the following properties:

  • mode
  • oobCode
  • apiKey
  • continueUrl
  • lang

My ideal solution is to send a custom template to the user upon registration with the generated verification link. Direct users to a custom handler page, and use the applyActionCode() function as shown in The Docs to verify the email (I hope this implicitly updates the emailVerified property on the Auth.User record.)


Solution

  • I have achieved this by creating the user and generating the link on the backend with the admin SDK.

    So your frontend would call a callable function or bespoke API endpoint for instance for the registration instead of using the SDK directly.

    The callable would go about this:

    • Creating the user in Auth: auth.createUser()
    • Creating the user in your DB (Firestore, Mongo etc.)
    • Assigning custom claims if required: auth.setCustomUserClaims
    • Building the link for signin: auth.generateSignInWithEmailLink()
    • Sending the email to an email transactional API

    You will need an ESP e.g Sendgrid, MailChimp, MailGun etc. for the last step. There you will have all the freedom to build your own templates.

    Please note that the generateSignInWithEmailLink will take care of verifying an email address and signing-in. It could therefore be used for login and registration.

    Cheers