Created
April 27, 2020 11:41
-
-
Save Serhansolo/5853162bbaeafe4ac0c8b2744634e3be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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