我一直在研究https://savvyapps.com/blog/definitive-guide-building-web-app-vuejs-firebase上的教程。以下代码对我而言不正确。
signup() {
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.$router.push('/dashboard')
}).catch(err => {
console.log(err)
})
}).catch(err => {
console.log(err)
})
}
有人可以帮我吗?
P.S:经过大量研究,我偶然发现这种方式使我创建了文档,但是内部的代码尚无法正常工作。此更改基于道格·史蒂文森(Doug Stevenson)在YouTube上有关承诺的视频。
const promise = fb.usersCollection.doc(user.user.uid).set({
name: this.signupForm.name,
title: this.signupForm.title
})
return promise.then(() => {
console.log('set ok')
this.$store.dispatch('fetchUserProfile')
this.performingRequest = false
this.$router.push('/dashboard')
}).catch(err => {
this.performingRequest = false
console.log(err)
this.errorMsg = err.message
})
P.S 2:下面的代码行有助于创建文档:
firebase.firestore().settings({ experimentalForceLongPolling: true })
Tylerhan回答了关于github的问题。这是解决方案:
async signup () {
this.performingRequest = true
await fb.auth.createUserWithEmailAndPassword(this.signupForm.email, this.signupForm.password).then(user => {
this.$store.commit('setCurrentUser', user.user)
})
const user = this.$store.getters.getCurrentUser
const userProfile = {
name: this.signupForm.name,
title: this.signupForm.title
}
fb.usersCollection.doc(user.uid).set(userProfile).then(() => {
this.$store.dispatch('fetchUserProfile')
this.performingRequest = false
this.$router.push('/dashboard')
}).catch(err => {
this.performingRequest = false
console.log(err)
this.errorMsg = err.message
})
}