Cristina
Cristina

Reputation: 1

Error in event handler for "click": "ReferenceError: user is not defined"

Please help me. I have been working for days trying to fix this error and keep ending back up at the same click handler error "user not defined" I just can't figure out what it means... this is a vuejs/vuex/vuetify/firestore project. Please any help would be appreciated.

relevant code from store/index.js

 updateUser({ commit, state },
        payload) {
        commit('setLoading', true);
        commit('clearError');
        firebase
            .firestore()
            .collection('users').doc(`users/${user.uid}`).add()
            .then((data, payload) => {
                const key = data.key;
                let displayName = payload.name;
                let address = payload.address;
                let city = payload.city;
                let state1 = payload.state1
                let zip = payload.zip
                let country = payload.country
                let company = payload.company
                let email = payload.email
                let phoneNumber = payload.phone
                commit('updateUser', {
                    id: key,
                    name: displayName,
                    phone: phoneNumber,
                    email: email,
                    address: address,
                    city: city,
                    state1: state1,
                    zip: zip,
                    country: country,
                    company: company
                })
            }).catch(err => {
                console.log(err)
            })
    },

Component code...

methods: {
  onUpdate() { 
    this.$store.dispatch("updateUser", { 
      email: this.email, 
      name: this.name, 
      company: this.company, 
      address: this.address, 
      city: this.city, 
      state1: this.state1, 
      zip: this.zip, 
      country: this.zip, 
      phone: this.phone, 
    });
  },

Upvotes: 0

Views: 1639

Answers (1)

Phil
Phil

Reputation: 164861

Assuming user is a state property, ie

state: {
  loading: false,
  errors: [],
  user: null      // 👈 here
},

then your Firestore docref should be

.doc(`users/${state.user.uid}`)

Since your action performs asynchronous operations, you should consider making it composable by having it return the promise, eg

updateUser({ commit, state }, payload) {
  commit('setLoading', true)
  commit('clearError')
  return firebase.firestore()... // 👈 note the "return" here

Upvotes: 1

Related Questions