Created
February 6, 2019 21:34
-
-
Save acidjazz/bd36e5a0731060d589b14906e8a12cf0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* store/index.js - vuex store | |
* Copyright (C) 2019 kevin olson <acidjazz@gmail.com> | |
* | |
* Distributed under terms of the APACHE license. | |
*/ | |
import Vuex from 'vuex' | |
const store = () => new Vuex.Store({ | |
actions: { | |
async refresh({ commit }) { | |
commit('user', (await this.$axios.get('me')).data.data) | |
} | |
}, | |
state: { | |
user: null, | |
modal: false, | |
intercept: true, | |
}, | |
mutations: { | |
user(state, user) { | |
state.user = user || false | |
}, | |
intercept(state, toggle) { | |
state.intercept = toggle || false | |
}, | |
modal(state, type) { | |
if (state.modal === type) { | |
return state.modal = true | |
} | |
state.modal = type || false | |
}, | |
}, | |
getters: { | |
auth (state) { | |
return state.user | |
}, | |
user (state) { | |
return state.user | |
}, | |
admin (state) { | |
if (!state.user || !state.user.is_admin) { | |
return false | |
} | |
return true | |
}, | |
}, | |
}) | |
export default store |
Author
acidjazz
commented
Feb 6, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment