Skip to content

Instantly share code, notes, and snippets.

@wrburgess
Forked from oleg-agapov/index.js
Created March 10, 2019 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wrburgess/94d5e416d74cb0cedb99df61c4384e23 to your computer and use it in GitHub Desktop.
Save wrburgess/94d5e416d74cb0cedb99df61c4384e23 to your computer and use it in GitHub Desktop.
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