javascriptfirebasefirebase-authentication

Generate custom email verification link with generateEmailVerificationLink firebase and react native


I want to send custom email verification email, so I followed the tutorial and this is my code:

import { getAuth } from "firebase/auth";

export async function sendVerificationEmail() {
  const actionCodeSettings = {
          url: 'https://www.example.com/cart?email=user@example.com&cartId=123',
          iOS: {
            bundleId: 'com.example.ios'
          },
          android: {
            packageName: 'com.example.android',
            installApp: true,
            minimumVersion: '12'
          },
          handleCodeInApp: true,
          dynamicLinkDomain: 'custom.page.link'
        };
    getAuth()
        .generateEmailVerificationLink('user@example.com', actionCodeSettings)
        .then(function(link) {
          console.log("link: ", link)
        })
      .catch((error) => {
        console.log("Could not generate email verification link: ", error);
      });

Right now I jus want to be able to generate the link and to output it. However I am having:

Error while sending verification EMAIL: [TypeError: (0, _auth.getAuth)().generateEmailVerificationLink is not a function (it is undefined)]

Can someone explain what I am doing wrong?


Solution

  • The API you're trying to use generateEmailVerificationLink doesn't exist in the Firebase Auth client library firebase/auth. It only exists in the Firebase Admin SDK, which is for use on backends only. Notice that the documentation you're following is for the Admin SDK.

    Your code will have to be moved to a backend using Firebase Admin instead.