如何仅注册使用Firebase javascript中的电子邮件链接验证了电子邮件地址的用户? [英] How to sign up only the users who have verified thier email addresses using the email link in Firebase javascript?

查看:47
本文介绍了如何仅注册使用Firebase javascript中的电子邮件链接验证了电子邮件地址的用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Vue,这是我的注册方法,它的作用是注册任何电子邮件ID ...这意味着即使我不拥有的电子邮件ID也可以注册,例如"test@example.com",因为没有电子邮件验证.

I'm using Vue and this is my sign up method, What it does is sign up any email id... meaning it signs up even email id's that i do not own like "test@example.com" because there is no email verification..

我已经在Firebase控制台中配置了电子邮件验证.现在,我希望注册方法发送验证邮件,并且仅在用户验证了电子邮件的情况下注册用户.

I have configured email verification in the Firebase console. Now i want the sign up method to send a verification mail and only register the user if he/she has verified the email .

我应该如何修改现有代码?我很困惑.

how should i modify my existing code? I'm confused.

import firebase from 'firebase'
export default {
  name: 'signup',
  data: function () {
    return {
      email: '',
      password: ''
    }
  },
  methods: {
    signup: function (e) {
      firebase.auth().createUserWithEmailAndPassword(this.email, this.password)
        .then(user => {
          alert(`Account created for ${user.user.email}`)
          this.$router.go({ path: this.$router.path })
        },
        err => {
          alert(err.message)
        })
      e.preventDefault()
    }
  }
}

推荐答案

发送验证电子邮件的标准方法是使用

The standard way to send a verification email is to use the sendEmailVerification() method.

因此,您将按以下方式修改代码:

So you would adapt your code as follows:

methods: {
   signup: function (e) {
      firebase.auth().createUserWithEmailAndPassword(this.email, this.password)
        .then(userCredential => {
            return userCredential.user.sendEmailVerification()
         })
         .then(function() {
            alert(`Account created for ${userCredential.user.email}`)
            this.$router.go({ path: this.$router.path })
         })
         .catch(err => {
            alert(err.message)
         })
      e.preventDefault()
   }
}

您会在文档中找到更多详细信息,尤其是有关

You will find more details in the documentation in particular on the parameter of type ActionCodeSettings that you can pass to the method.

请注意,您可以在Firebase控制台中自定义电子邮件的内容.

Note also that you can customize the content of the email in the Firebase console.

这篇关于如何仅注册使用Firebase javascript中的电子邮件链接验证了电子邮件地址的用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆