I have a login method inside a Vue component that uses firebase to sign in a user. I'm using computed properties user
, message
, and hasErrors
. When this method runs, It goes into the catch
function, but this error comes up:
Uncaught TypeError: Cannot set property 'message' of undefined
. I've tried changing the vuex state directly (because that's what the computed prop does), but this gives the same error. Here is the method I'm using:
login: function (event) {
// ... more stuff
// Sign-in the user with the email and password
firebase.auth().signInWithEmailAndPassword(this.email, this.password)
.then(function (data) {
this.user = firebase.auth().currentUser
}).catch(function (error) {
this.message = error.message
this.hasErrors = true
})
// ...
}
Here's what the computed prop looks like:
message: {
get () {
return this.auth.message // mapState(['auth'])
},
set (value) {
this.$store.commit('authMessage', value)
}
}
I'm pretty sure the problem has to do with it being inside a Promise
.
So how can I access computed properties within the firebase Promise
?
this
is not what you think it is inside the callback-probably want to read up on howthis
works, and how to remedy it. – Dave Newton