'Firebase authentication email customisation

I'm using firebase auth in my app and i'm setting up password-less email sign up.

I have managed to set the email from my own domain but how do i change the text sent in the email for magic link? I can see the configuration for the other template emails but not this one.

The email in question is this one:

Hello,

We received a request to sign in to teamname using this email address. If you want to sign in with your youremail account, click this link: link

If you did not request this link, you can safely ignore this email.

Thanks,


Solution 1:[1]

There is no way to edit the email template. The reason for this is that this allows bad actors to use Firebase to spam people, which would put the service at risk.

To control what message gets sent, you'll have to send it yourself and handle the verification flow with a custom email action handler. See How to modify Email Confirmation message - Firebase.

You could also take full control of the verification flow, and then use the Admin SDK to set the emailVerified flag of the user's profile.

Solution 2:[2]

Following on from Frank's answer, you will have to create your own email action link using the Firebase Admin SDK and then put that link in your custom email which you will then send using whatever service (Sendgrid, Mailgun, etc.).

See how to create the action link here: Generating Email Action Links

Solution 3:[3]

the only way to customize your email body is to install firebase extension called Trigger Email but it'll put you on the Blaze plan because it makes requests to third-party APIs, and as they specified on the extension's page you'll only be charged for usage that exceeds Firebase's free tier.

Solution 4:[4]

There are two ways to customize the email body when using the Firebase authentication service. However, the drawback is that you will have to create a backend to send the email yourself rather than just using a function from the SDK that handles everything automatically.

  1. Generate email action links: This is the most efficient method, it requires that you use the Firebase Admin SDK to generate a link that will be embedded in emails sent to your users. Here is an example code that shows how to create an API to send customized verification emails using Express as the backend:

    // Creating a POST route that sends customized verification emails
    app.post('/send-custom-verification-email', async (req, res) => {
      const {userEmail, redirectUrl} = req.body
    
      const actionCodeSettings = {
        url: redirectUrl
      }
    
      try{
        // generate action like with the Firebase Admin SDK
        const actionLink =  await getAuth()
        .generateEmailVerificationLink(userEmail, actionCodeSettings)
    
        // embedding action link to customized verification email template
        const template = await ejs.renderFile('views/verify-email.ejs', {
          actionLink
        })
    
        // send verification email using  SendGrid, Nodemailer, etc.
        await sendVerificationEmail(userEmail, template, actionLink)
    
        res.status(200).json({message:'Email successfully sent'})
      }catch(error){
        // handle errors
      }
    })
    
    

    You can read more about it in the article I wrote here

  2. Take full control over the workflow: With this, the Firebase Admin SDK won't be used to generate an action link, but rather, you will generate the link yourself and create an API that uses the Admin SDK to handle the action to be taken whenever the link is clicked.

    To do this you will have to create two API routes. One is a route that sends the emails and the other is a route that uses the Firebase Admin SDK to handle the action to be taken when the link attached to the email is clicked.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Frank van Puffelen
Solution 2 mykfmn
Solution 3 Mina Ragaie
Solution 4