0

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)

Error report

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'
      }
    }
  }

1 Answer 1

1
db.collection("users").doc(cred.user.uid).set(data).then({
     db.collection("users").doc(this.slug).delete()
})

then expect its parameter to be a function, I reckon it where your error come from, the correct should be:

db.collection("users").doc(cred.user.uid).set(data).then(() => {
     db.collection("users").doc(this.slug).delete()
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.