I am trying to create a listenAuth function that looks onAuthStateChanged "in firebase to notify vuex store strong> when a user has logged in or out. As far as I can tell, I only change state.authData using a mutation handler if I'm missing something ?
I get an error message:
[vuex] Do not mutate vuex store state outside mutation handlers.
Here is my javascript App.vue (from my component)
<script> // import Navigation from './components/Navigation' import * as actions from './vuex/actions' import store from './vuex/store' import firebase from 'firebase/app' export default { store, ready: function () { this.listenAuth() }, vuex: { actions, getters: { authData: state => state.authData, user: state => state.user } }, components: { // Navigation }, watch: { authData (val) { if (!val) { this.redirectLogin this.$route.router.go('/login') } } }, methods: { listenAuth: function () { firebase.auth().onAuthStateChanged((authData) => { this.changeAuth(authData) }) } } } </script>
Here is my action (changeAuth) function
export const changeAuth = ({ dispatch, state }, authData) => { dispatch(types.AUTH_CHANGED, authData) }
Here is my store (parts that matter)
const mutations = { AUTH_CHANGED (state, authData) { state.authData = authData } } const state = { authData: {} }
source share