diff --git a/src/App.vue b/src/App.vue index 1bab289..fd8151f 100644 --- a/src/App.vue +++ b/src/App.vue @@ -9,10 +9,12 @@ import { mapActions } from 'vuex' export default { name: 'App', methods: { - ...mapActions('settings', ['getSettings']) + ...mapActions('settings', ['getSettings']), + ...mapActions('auth', ['handleAuthStateChange']) }, mounted () { this.getSettings() + this.handleAuthStateChange() } } diff --git a/src/layouts/Layout.vue b/src/layouts/Layout.vue index 84139b1..e4e1ee9 100644 --- a/src/layouts/Layout.vue +++ b/src/layouts/Layout.vue @@ -6,12 +6,20 @@ Awesome Todo + @@ -57,6 +65,7 @@ diff --git a/src/store/store-auth.js b/src/store/store-auth.js index c55cb80..ec4ec15 100644 --- a/src/store/store-auth.js +++ b/src/store/store-auth.js @@ -1,13 +1,17 @@ import { firebaseAuth } from 'boot/firebase' const state = { + loggedIn: false } const mutations = { + setLoggedIn (state, value) { + state.loggedIn = value + } } const actions = { - registerUser ({ state }, payload) { + registerUser ({ commit }, payload) { firebaseAuth.createUserWithEmailAndPassword(payload.email, payload.password) .then(response => { console.log('response: ', response) @@ -16,7 +20,7 @@ const actions = { console.log('error.message: ', error) }) }, - loginUser ({ state }, payload) { + loginUser ({ commit }, payload) { firebaseAuth.signInWithEmailAndPassword(payload.email, payload.password) .then(response => { console.log('response: ', response) @@ -24,6 +28,15 @@ const actions = { .catch(error => { console.log('error.message: ', error) }) + }, + handleAuthStateChange ({ commit }) { + firebaseAuth.onAuthStateChanged(function (user) { + if (user) { + commit('setLoggedIn', true) + } else { + commit('setLoggedIn', false) + } + }) } }