fixing auth-routes example

This commit is contained in:
kodekrendel 2017-05-10 23:06:43 -04:00
parent 892543eb1d
commit 2f881dfb31

View File

@ -1,16 +1,19 @@
import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios' import axios from 'axios'
export const state = { Vue.use(Vuex)
authUser: null
}
export const mutations = { const store = new Vuex.Store({
state: {
authUser: null
},
mutations: {
SET_USER: function (state, user) { SET_USER: function (state, user) {
state.authUser = user state.authUser = user
} }
} },
actions: {
export const actions = {
nuxtServerInit ({ commit }, { req }) { nuxtServerInit ({ commit }, { req }) {
if (req.session && req.session.authUser) { if (req.session && req.session.authUser) {
commit('SET_USER', req.session.authUser) commit('SET_USER', req.session.authUser)
@ -30,12 +33,13 @@ export const actions = {
} }
}) })
}, },
logout ({ commit }) { logout ({ commit }) {
return axios.post('/api/logout') return axios.post('/api/logout')
.then(() => { .then(() => {
commit('SET_USER', null) commit('SET_USER', null)
}) })
} }
} }
})
export default store