Changed login from rest to firebase lib
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import Vue from "vue";
|
import Vue from "vue";
|
||||||
import Vuex from "vuex";
|
import Vuex from "vuex";
|
||||||
import axios from "axios";
|
|
||||||
|
import { getAuth, signInWithEmailAndPassword, signOut } from "firebase/auth";
|
||||||
|
|
||||||
Vue.use(Vuex);
|
Vue.use(Vuex);
|
||||||
|
|
||||||
@@ -17,24 +18,31 @@ export default new Vuex.Store({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
loginUser({ commit }, auth) {
|
loginUser({ commit }, data) {
|
||||||
axios.post(
|
const auth = getAuth();
|
||||||
"https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=" + process.env.VUE_APP_FIREBASE_API_KEY,
|
|
||||||
{
|
signInWithEmailAndPassword(auth, data.email, data.pass)
|
||||||
email: auth.email,
|
.then((userCredential) => {
|
||||||
password: auth.pass,
|
// Signed in
|
||||||
returnSecureToken: true,
|
commit("storeUser", userCredential.user);
|
||||||
}
|
// ...
|
||||||
).then((res) => {
|
})
|
||||||
console.log(res);
|
.catch((error) => {
|
||||||
commit('storeUser', res.data);
|
const errorCode = error.code;
|
||||||
}).catch((e) => {
|
const errorMessage = error.message;
|
||||||
console.error(e);
|
});
|
||||||
})
|
|
||||||
},
|
},
|
||||||
logout({ commit }) {
|
logout({ commit }) {
|
||||||
commit('clearUserData');
|
const auth = getAuth();
|
||||||
}
|
signOut(auth)
|
||||||
|
.then(() => {
|
||||||
|
// Sign-out successful.
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
// An error happened.
|
||||||
|
});
|
||||||
|
commit("clearUserData");
|
||||||
|
},
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
auth: (state) => state.user !== undefined,
|
auth: (state) => state.user !== undefined,
|
||||||
|
|||||||
Reference in New Issue
Block a user