[Vuejs]-How to store firebase token in Vuex store

3👍

My guess:

   user.getIdToken().then(function(idToken) {
     this.$store.commit('setStoreToken', idToken)
     return idToken
   });

You dont use an arrow function, that means that this is binded to the function itself you can either use an arrow function or you create a variable infront of it like this const self = this

   user.getIdToken().then((idToken)=>{
     this.$store.commit('setStoreToken', idToken)
     return idToken
   });

Or you do it like this:

   const self = this;
   user.getIdToken().then(function(idToken) {
     self.$store.commit('setStoreToken', idToken)
     return idToken
   });

Leave a comment