47 lines
873 B
JavaScript
47 lines
873 B
JavaScript
import Vue from 'vue'
|
|
import Vuex from 'vuex'
|
|
|
|
import api from '../lib/Api';
|
|
|
|
Vue.use(Vuex);
|
|
|
|
export default new Vuex.Store({
|
|
strict: process.env.NODE_ENV !== 'production',
|
|
state: {
|
|
loading: false,
|
|
error: null,
|
|
authChecked: false,
|
|
user: null
|
|
},
|
|
getters: {
|
|
isLoading(state) {
|
|
return state.loading === true;
|
|
},
|
|
isLoggedIn(state) {
|
|
return state.user !== null;
|
|
},
|
|
isAdmin(state) {
|
|
return state.user !== null && state.user.admin === true;
|
|
}
|
|
},
|
|
mutations: {
|
|
setLoading(state, value) {
|
|
state.loading = value;
|
|
},
|
|
|
|
setError(state, value) {
|
|
state.error = value;
|
|
},
|
|
|
|
setUser(state, user) {
|
|
state.authChecked = true;
|
|
state.user = user;
|
|
}
|
|
},
|
|
actions: {
|
|
logout({commit}) {
|
|
return api.getLogout()
|
|
.then(() => commit("setUser", null));
|
|
}
|
|
}
|
|
}); |