1

I am making a React Native app where you can create accounts via Firebase authentication. I am try to set up a way to verify your email. I thought the code below would work, but it doesn't work. Anyone know the solution to this:

Code:

async function handleSignUp() {
    await createUserWithEmailAndPassword(auth, email, password)
      .then((userCredentials) => {
        let user = auth.currentUser;

        const actionCodeSettings = {
          url: `${configData.BASE_URL}/sign-in/?email=${user.email}`,
        };

        auth.currentUser.sendEmailVerification(actionCodeSettings).then(() => {
          alert("Verification link has been sent to your email");
        });
      })
      .catch((error) => alert(error.message));
  }
DevBaddy
  • 173
  • 9
  • If you don't get an error from the `sendEmailVerification` API call, the email as almost certainly sent. If you don't see it show up in your inbox, it was probably marked as spam. Check the spam folder of your inbox and with your system administrator to see where the message ended up. See https://stackoverflow.com/questions/72922475/why-did-this-code-fail-to-send-password-reset-link-in-firebase/72922603#72922603 – Frank van Puffelen Aug 16 '22 at 14:21
  • I am getting this error: _config.auth.currentUser.sendEmailVerification is not a function. (In '_config.auth.currentUser.sendEmailVerification(actionCodeSettings)', '_config.auth.currentUser.sendEmailVerification' is undefined) @FrankvanPuffelen – DevBaddy Aug 16 '22 at 14:30

1 Answers1

2

You're using the v9 or later SDK, which uses a modular syntax like you see here: await createUserWithEmailAndPassword(auth, email, password).

Similar to createUserWithEmailAndPassword, sendEmailVerification is a top-level function too in this API, so the syntax is:

sendEmailVerification(auth.currentUser, actionCodeSettings).then(() => {
  alert("Verification link has been sent to your email");
});

This API is quite well covered in the Firebase documentation on sending an email verification link, so I recommend keeping that handy while coding.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807