Простой способ сделать это объяснен здесь
Однако я испытываю трудности с попыткой вызвать отписку в onAuthStateChanged
, который находится в другом модуле vuex
store / user. js
...
onAuthStateChanged({ commit, dispatch }, { authUser }) {
if (!authUser) {
commit('RESET_STORE')
this.$router.push('/')
return
}
commit('SET_AUTH_USER', { authUser })
dispatch('database/getUserItems', null, { root: true })
this.$router.push('/home')
}
...
store / database. js
...
getUserItems({ state, commit }, payload) {
const unsubscribe = this.$fireStore
.collection('useritems')
.where('owner', '==', this.state.user.authUser.uid)
.onSnapshot(
(querySnapshot) => {
querySnapshot.forEach(function(doc) {
// STUFF
},
(error) => {
console.log(error)
}
)
},
...
Как ссылаться на unsubscribe()
от пользователя. js модуль, когда пользователь выходит из системы (authUser undefined)?