diff --git a/src/store/index.ts b/src/store/index.ts index 6621a42..d85cd4c 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -1,16 +1,40 @@ import Vue from "vue"; import Vuex from "vuex"; +import axios from "axios"; Vue.use(Vuex); export default new Vuex.Store({ state: { - token: "yes", + user: undefined, + }, + mutations: { + storeUser(state, payload) { + state.user = payload; + }, + cleanUserData(state) { + state.user = undefined; + }, + }, + actions: { + loginUser({ commit }, auth) { + axios.post( + "https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=" + process.env.VUE_APP_FIREBASE_API_KEY, + { + email: auth.email, + password: auth.pass, + returnSecureToken: true, + } + ).then((res) => { + console.log(res); + commit('storeUser', res.data); + }).catch((e) => { + console.error(e); + }) + }, }, - mutations: {}, - actions: {}, getters: { - auth: (state) => state.token !== undefined, + auth: (state) => state.user !== undefined, }, modules: {}, }); diff --git a/src/views/Login.vue b/src/views/Login.vue index 6e9fead..9f188ae 100644 --- a/src/views/Login.vue +++ b/src/views/Login.vue @@ -1,11 +1,84 @@ - \ No newline at end of file +