import Vue from 'vue';
import Vuex from 'vuex';
import axios from 'axios';

Vue.use(Vuex);

export default {
  namespaced: true,
  state: {
    auth: {}
  },
  mutations: {
    setAuthentication(state, auth) {
      state.auth = auth;
    }
  },
  getters: {},
  actions: {
    getAuthentication({
      commit
    }) {
      axios
        .get('api/Authentication')
        .then(result => commit('setAuthentication', result.data));
    },
    Login({
      commit
    }, auth) {
      //   axios
      //     .post('api/Authentication', auth)
      //     .then(result => commit('setAuthentication', result.data));
      axios({
        url: 'api/Authentication',
        data: {
          emailAddress: auth.emailAddress,
          password: auth.password,
        },
        method: 'POST',
      }).then((resp) => {
        commit('setAuthentication', resp.data);
      });
    }
  }
}
