在Firebase中创建用户给我一个错误 [英] Creating user in Firebase gives me an error

查看:56
本文介绍了在Firebase中创建用户给我一个错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在关注精明的应用程序教程以学习Vue.js.本教程将Firebase与Firestore结合使用.由于Firestore处于Beta版(如本教程所述),因此可能会发生更改-我认为这里可能就是这种情况.

So I'm following a Savvy Apps tutorial in order to learn Vue.js. This tutorial uses Firebase with Firestore. Since Firestore is in Beta (as the tutorial says), changes might happen - and I think that might be the case here.

无论如何,我都试图注册一个新用户.我填写表格并单击注册",然后收到此错误消息:

In any case, I'm trying to sign up a new user. I fill out the form and click 'Sign up' and I get this error message:

错误:函数CollectionReference.doc()要求其第一个参数为字符串类型,但它是:未定义

Error: Function CollectionReference.doc() requires its first argument to be of type string, but it was: undefined

但是在Firebase中,我看到已经创建了该用户.那么,为什么我会收到此错误消息?什么是第一个论点?

But looking in Firebase, I see that the user has been created. So why do I get this error message? What is the first argument?

注册代码如下:

  signup() {
    this.performingRequest = true;
    fb.auth.createUserWithEmailAndPassword(this.signupForm.email, this.signupForm.password).then(user => {
      this.$store.commit('setCurrentUser', user);
      // create user obj
      fb.usersCollection.doc(user.uid).set({
        name: this.signupForm.name,
        title: this.signupForm.title
      }).then(() => {
        this.$store.dispatch('fetchUserProfile');
        this.performingRequest = false;
        this.$router.push('/dashboard')
      }).catch(err => {
        console.log(err);
        this.performingRequest = false;
        this.errorMsg = err.message
      })
    }).catch(err => {
      console.log(err);
      this.performingRequest = false;
      this.errorMsg = err.message
    })
  },

让我知道您是否需要更多代码-这是我第一次测试Vue.js.

Let me know if you need more code - this is the first time I'm testing Vue.js.

推荐答案

Promise UserCredential . UserCredential firebase.User 对象具有属性user.

createUserWithEmailAndPassword() returns a Promise containing a UserCredential. UserCredential has a property user for the firebase.User object.

您需要对代码进行适当的更改才能正确访问UID:

You need to make the appropriate changes to your code to correctly access the UID:

  signup() {
    this.performingRequest = true;
    fb.auth.createUserWithEmailAndPassword(this.signupForm.email, this.signupForm.password)
    .then(credential=> {  // CHANGED
      this.$store.commit('setCurrentUser', credential.user);  // CHANGED
      // create user obj
      fb.usersCollection.doc(credential.user.uid).set({  //CHANGED
        name: this.signupForm.name,
        title: this.signupForm.title
      }).then(() => {
        this.$store.dispatch('fetchUserProfile');
        this.performingRequest = false;
        this.$router.push('/dashboard')
      }).catch(err => {
        console.log(err);
        this.performingRequest = false;
        this.errorMsg = err.message
      })
    }).catch(err => {
      console.log(err);
      this.performingRequest = false;
      this.errorMsg = err.message
    })
  },

这篇关于在Firebase中创建用户给我一个错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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