I cannot find the syntax error in this signup method. It's been more than an hour now.
.then(() => {
db.collection("users").doc(this.slug).get().then((doc) => {
let data = doc.data()
db.collection("users").doc(cred.user.uid).set(data).then({
db.collection("users").doc(this.slug).delete()
})
})
})
This code above basically gets the newly created document, then puts the data into let data. After that, it creates a new document with the User UID as the name passes the data to it and then just deletes the old document. A syntax error lies in that code, but the indicator says, it is the dot between db and collection (db.collection)
methods: {
signup(){
console.log('signup ran')
if(this.heroName){
this.slug = slugify(this.heroName, {
replacement: '-',
remove: /[$*_+~.()'"!\-:@]/g,
lower: true
})
console.log(this.slug)
let ref = db.collection('users').doc(this.slug)
ref.get().then(doc => {
if(doc.exists){
this.feedback = 'This alias already exists'
} else {
// this alias does not yet exists in the db
this.feedback = 'This alias is free to use'
firebase.auth().createUserWithEmailAndPassword(this.email, this.password)
.then(cred => {
ref.set({
alias: this.heroName,
user_id: cred.user.uid,
gemcount: 15
})
// FIXME: error below
.then(() => {
db.collection("users").doc(this.slug).get().then((doc) => {
let data = doc.data()
db.collection("users").doc(cred.user.uid).set(data).then({
db.collection("users").doc(this.slug).delete()
})
})
})
.then(() => {
this.$router.push({ name: 'Core' })
})
})
.catch(err => {
console.log(err)
this.feedback = err.message;
})
}
})
} else {
this.feedback = 'Please enter a heroName'
}
}
}