所以我正在关注精明的应用程序教程以学习 Vue.js。本教程使用 Firebase 和 Firestore。由于 Firestore 处于 Beta 阶段(正如教程所述),因此可能会发生变化 - 我认为这里可能就是这种情况。
无论如何,我正在尝试注册一个新用户。我填写了表格并单击“注册”,然后收到以下错误消息:
错误:函数 CollectionReference.doc() 要求其第一个参数为字符串类型,但它是:未定义
但在 Firebase 中查看,我看到用户已创建。那么为什么我会收到此错误消息呢?第一个论点是什么?
注册代码如下所示:
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。
创建用户与电子邮件和密码()返回一个Promise
含有一个用户凭证. UserCredential
有财产user
为了firebase.用户 object.
您需要对代码进行适当的更改才能正确访问 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
})
},
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)