-
-
Save wrburgess/3aae20ed31c346905afbed249419fc57 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Vue from 'vue' | |
import Vuex from 'vuex' | |
import firebase from 'firebase' | |
import router from '@/router' | |
Vue.use(Vuex) | |
export const store = new Vuex.Store({ | |
state: { | |
appTitle: 'My Awesome App', | |
user: null, | |
error: null, | |
loading: false | |
}, | |
mutations: { | |
setUser (state, payload) { | |
state.user = payload | |
}, | |
setError (state, payload) { | |
state.error = payload | |
}, | |
setLoading (state, payload) { | |
state.loading = payload | |
} | |
}, | |
actions: { | |
userSignUp ({commit}, payload) { | |
commit('setLoading', true) | |
firebase.auth().createUserWithEmailAndPassword(payload.email, payload.password) | |
.then(firebaseUser => { | |
commit('setUser', {email: firebaseUser.user.email}) | |
commit('setLoading', false) | |
router.push('/home') | |
commit('setError', null) | |
}) | |
.catch(error => { | |
commit('setError', error.message) | |
commit('setLoading', false) | |
}) | |
}, | |
userSignIn ({commit}, payload) { | |
commit('setLoading', true) | |
firebase.auth().signInWithEmailAndPassword(payload.email, payload.password) | |
.then(firebaseUser => { | |
commit('setUser', {email: firebaseUser.user.email}) | |
commit('setLoading', false) | |
commit('setError', null) | |
router.push('/home') | |
}) | |
.catch(error => { | |
commit('setError', error.message) | |
commit('setLoading', false) | |
}) | |
} | |
}, | |
getters: {} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment