From 5ca97c2f3010d19743aabb970bc81635ab88ec11 Mon Sep 17 00:00:00 2001 From: Kamil Klecha Date: Fri, 15 Oct 2021 00:18:44 +0200 Subject: [PATCH] Added firebase login --- src/store/index.ts | 32 +++++++++++++++--- src/views/Login.vue | 81 ++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 105 insertions(+), 8 deletions(-) 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 +