Changed login from rest to firebase lib

This commit is contained in:
Kamil Klecha
2021-10-16 22:18:26 +02:00
parent b46123d415
commit a1efc79329

View File

@@ -1,6 +1,7 @@
import Vue from "vue";
import Vuex from "vuex";
import axios from "axios";
import { getAuth, signInWithEmailAndPassword, signOut } from "firebase/auth";
Vue.use(Vuex);
@@ -17,24 +18,31 @@ export default new Vuex.Store({
},
},
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);
})
loginUser({ commit }, data) {
const auth = getAuth();
signInWithEmailAndPassword(auth, data.email, data.pass)
.then((userCredential) => {
// Signed in
commit("storeUser", userCredential.user);
// ...
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
});
},
logout({ commit }) {
commit('clearUserData');
}
const auth = getAuth();
signOut(auth)
.then(() => {
// Sign-out successful.
})
.catch((error) => {
// An error happened.
});
commit("clearUserData");
},
},
getters: {
auth: (state) => state.user !== undefined,