【问题标题】:Firebase 5.8^ sendEmailVerificationFirebase 5.8^ 发送电子邮件验证
【发布时间】:2019-06-24 08:50:27
【问题描述】:

我正在尝试让firebase 通过电子邮件创建用户并发送验证电子邮件。 它已经改变了,我相信版本 5+

我似乎无法让它发挥作用。

谁能帮忙解释一下我哪里出错了?

我不断收到以下错误消息

TypeError: user.sendEmailVerification 不是函数

这是我的 TS 文件。

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!');
});

【问题讨论】:

    标签: angular typescript firebase firebase-authentication


    【解决方案1】:

    最后,我找到了这个解决方案。

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

    【讨论】:

    • 为我工作。看起来像以前的版本返回用户,但现在它返回一个具有用户属性的不同对象。
    【解决方案2】:

    在 Firebase 9 中有单独的方法

    import { sendEmailVerification } from "firebase/auth"; 
    

    例子:

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

    【讨论】:

      【解决方案3】:
      .then((userData)=>{   
         firebase.auth().currentUser.sendEmailVerification()
      

      这对我有用

      【讨论】:

        猜你喜欢
        • 2018-11-21
        • 1970-01-01
        • 1970-01-01
        • 2017-09-09
        • 2018-01-01
        • 2020-12-12
        • 2020-08-06
        • 2017-03-17
        • 2019-03-13
        相关资源
        最近更新 更多