Skip to content

Instantly share code, notes, and snippets.

@acidjazz
Created February 6, 2019 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acidjazz/bd36e5a0731060d589b14906e8a12cf0 to your computer and use it in GitHub Desktop.
Save acidjazz/bd36e5a0731060d589b14906e8a12cf0 to your computer and use it in GitHub Desktop.
/*
* 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
@acidjazz
Copy link
Author

acidjazz commented Feb 6, 2019

export const actions  = {
  async refresh({ commit }) {
    commit('user', (await this.$axios.get('me')).data.data)
  }
}

export const state = () => ({
  user: null,
  modal: false,
  intercept: true,
})

export const 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
  },
}

export const getters = {
  auth (state) {
    return state.user
  },
  user (state) {
    return state.user
  },
  admin (state) {
    if (!state.user || !state.user.is_admin) {
      return false
    }
    return true
  },
}```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment