text: import Vue from 'vue'
  import Vuex from 'vuex'
  import axios from 'axios'
  Vue.use(Vuex)
  
  const store = new Vuex.Store({
      state: {
          token: localStorage.getItem('access_token') || null
      },
      getters: {
          loggedIn(state) {
              return state.token !== null
          }
      },
      mutations: {
          retrieveToken(state, token) {
              state.token = token
          },
          destroyToken(state) {
              state.token = null
          }
      },
      actions: {
          retrieveToken(context, credentials) {
  
              return new Promise((resolve, reject) => {
                  axios.post('/api/login', {
                          name: credentials.name,
                          password: credentials.password,
                          remember_me : true
                      })
                      .then(response => {
                          //console.log(response)
                          const token = response.data.access_token
                          localStorage.setItem('access_token', token)
                          context.commit('retrieveToken', token)
  
                          resolve(response)
                      })
                      .catch(error => {
                          //console.log(error)
                          reject(error)
                      })
              })
  
          },
          destroyToken(context) {
  
              if (context.getters.loggedIn) {
  
                  return new Promise((resolve, reject) => {
                      axios.post('/api/logout', '', {
                              headers: {
                                  Authorization: "Bearer " + context.state.token
                              }
                          })
                          .then(response => {
                              //console.log(response)
                              localStorage.removeItem('access_token')
                              context.commit('destroyToken')
  
                              resolve(response)
                          })
                          .catch(error => {
                              //console.log(error)
                              localStorage.removeItem('access_token')
                              context.commit('destroyToken')
  
                              reject(error)
                          })
                  })
  
              }
          }
      }
  })
  
  export default store
  