Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9bab001

Browse files
committed
code modules vuex shared & user
1 parent 3f5f328 commit 9bab001

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed

‎src/store/shared/index.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
export default {
2+
state: {
3+
loading: false,
4+
error: null
5+
},
6+
mutations: {
7+
setLoading (state, payload) {
8+
state.loading = payload
9+
},
10+
setError (state, payload) {
11+
state.error = payload
12+
},
13+
clearError (state) {
14+
state.error = null
15+
}
16+
},
17+
actions: {
18+
clearError ({commit}) {
19+
commit('clearError')
20+
}
21+
},
22+
getters: {
23+
loading (state) {
24+
return state.loading
25+
},
26+
error (state) {
27+
return state.error
28+
}
29+
}
30+
}

‎src/store/user/index.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import * as firebase from 'firebase'
2+
3+
export default {
4+
state: {
5+
user: null
6+
},
7+
mutations: {
8+
setUser (state, payload) {
9+
state.user = payload
10+
}
11+
},
12+
actions: {
13+
signUserUp ({commit}, payload) {
14+
commit('setLoading', true)
15+
commit('clearError')
16+
firebase.auth().createUserWithEmailAndPassword(payload.email, payload.password)
17+
.then(
18+
user => {
19+
commit('setLoading', false)
20+
const newUser = {
21+
id: user.uid,
22+
name: user.displayName,
23+
email: user.email,
24+
photoUrl: user.photoURL,
25+
fbKeys: {}
26+
}
27+
commit('setUser', newUser)
28+
}
29+
)
30+
.catch(
31+
error => {
32+
commit('setLoading', false)
33+
commit('setError', error)
34+
console.log(error)
35+
}
36+
)
37+
},
38+
signUserIn ({commit}, payload) {
39+
commit('setLoading', true)
40+
commit('clearError')
41+
firebase.auth().signInWithEmailAndPassword(payload.email, payload.password)
42+
.then(
43+
user => {
44+
commit('setLoading', false)
45+
const newUser = {
46+
id: user.uid,
47+
name: user.displayName,
48+
email: user.email,
49+
photoUrl: user.photoURL,
50+
fbKeys: {}
51+
}
52+
commit('setUser', newUser)
53+
}
54+
)
55+
.catch(
56+
error => {
57+
commit('setLoading', false)
58+
commit('setError', error)
59+
console.log(error)
60+
}
61+
)
62+
},
63+
autoSignIn ({commit}, payload) {
64+
commit('setUser', {
65+
id: payload.uid,
66+
name: payload.displayName,
67+
email: payload.email,
68+
photoUrl: payload.photoURL,
69+
fbKeys: {}
70+
})
71+
},
72+
logout ({commit}) {
73+
firebase.auth().signOut()
74+
commit('setUser', null)
75+
}
76+
},
77+
getters: {
78+
user (state) {
79+
return state.user
80+
}
81+
}
82+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /