Mark
Mark

Reputation: 159

Firebase 5.8^ sendEmailVerification

I am trying to make firebase create user by email and send the verification email. It has changed I believe in version 5+

I cannot seem to get it to function.

Can someone help explain where am I going wrong?

The following error message I keep getting is

TypeError: user.sendEmailVerification is not a function

This is my TS file.

onSubmit(form: NgForm) {

const fullname = form.value.fullname;
const email = form.value.email;
const password = form.value.password;


firebase.auth().createUserWithEmailAndPassword(email, password)
.then(function(user) {
    user.sendEmailVerification();
})
.then(function () {
    console.log('User signup success');
    alert('Signed Up');
})
.catch(function (err) {
    console.log(err);
    alert('Error!');
});

Upvotes: 3

Views: 1956

Answers (3)

kossam kafesu
kossam kafesu

Reputation: 11

.then((userData)=>{   
   firebase.auth().currentUser.sendEmailVerification()

this worked for me

Upvotes: 0

Elmatsidis Paul
Elmatsidis Paul

Reputation: 465

In Firebase 9 there is separate method

import { sendEmailVerification } from "firebase/auth"; 

Example:

       sendEmailVerification(auth.currentUser)
           .then(() => {
               // Your code is here            
           })
           .catch((error) => {
               console.log('Email verification error', error);
           });

Upvotes: 5

Mark
Mark

Reputation: 159

In the end, I found this solution.

firebase.auth().createUserWithEmailAndPassword(email, password)
    .then(userData => {
        userData.user.sendEmailVerification();
            console.log(userData);
    })
    .catch(err => {
        console.log(err);
    });

Upvotes: 8

Related Questions