登录时出现Firebase + Firestore错误

时间:2018-08-21 21:19:42

标签: javascript firebase google-cloud-firestore

我用displayWordfirebase创建了一个登录系统,但是如果我要登录或注册,则会发生此错误:

enter image description here

我删除了一些代码,但是它不起作用

注册代码:

firestore

错误:

enter image description here

2 个答案:

答案 0 :(得分:2)

createUserWithEmailAndPassword()方法返回一个UserCredential,如doc中所述。 UserCredential的{​​{3}}解释说,它包含一个User对象。

因此,您应该执行以下操作。

signup() {
       this.performingRequest = true

       fb.auth.createUserWithEmailAndPassword(this.signupForm.email, this.signupForm.password).then(userCredential => {
        this.$store.commit('setCurrentUser', userCredential.user) //Or userCredential, depending on what you want to save.

                // create user obj
                fb.usersCollection.doc(userCredential.user.uid).set({
                  name: this.signupForm.name,
                  email: this.signupForm.email
                }).then(() => {
                    this.$store.dispatch('fetchUserProfile')
                    this.performingRequest = false
                    this.$router.push('/world')
                }).catch(err => {
                    console.log(err)
                    this.performingRequest = false
                    this.errorMsg = err.message
                })
            }).catch(err => {
                console.log(err)
                this.performingRequest = false
                this.errorMsg = err.message
            })
        },

答案 1 :(得分:0)

将user.uid转换为String:

fb.usersCollection.doc(String(user.uid))