Skip to content

Instantly share code, notes, and snippets.

@Serhansolo
Created April 27, 2020 11:41
Show Gist options
  • Save Serhansolo/5853162bbaeafe4ac0c8b2744634e3be to your computer and use it in GitHub Desktop.
Save Serhansolo/5853162bbaeafe4ac0c8b2744634e3be to your computer and use it in GitHub Desktop.
import firebase from "firebase/app";
const actions = {
authAction({ commit }) {
firebase.auth().onAuthStateChanged(user => {
if (user) {
commit("setUser", user);
} else {
commit("setUser", null);
}
});
},
signUpAction({ commit }, payload) {
firebase
.auth()
.createUserWithEmailAndPassword(payload.email, payload.password)
.catch(error => {
commit("setError", error.message);
});
},
signInAction({ commit }, payload) {
firebase
.auth()
.signInWithEmailAndPassword(payload.email, payload.password)
.catch(error => {
commit("setError", error.message);
});
},
signOutAction({ commit }) {
firebase
.auth()
.signOut()
.then(() => {
commit("setUser", null);
})
.catch(error => {
commit("setError", error.message);
});
}
};
export default actions;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment