-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
44 lines (39 loc) · 1.08 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import Vuex from 'vuex';
import md5 from 'md5';
export const state = () => ({
posts:[],
token: "",
user: null,
});
export const mutations = {
setPosts(state, posts){
state.posts = posts;
},
setToken(state, token) {
state.token = token;
},
setUser(state, user){
state.user = user;
},
};
export const actions = {
async loadPosts({commit},apiUrl){
const blogPosts = await this.$axios.$get(apiUrl);
commit("setPosts", blogPosts);
},
async authenticateUser({commit}, userPayload){
try{
const authUserData = await this.$axios.$post('/register/',userPayload);
const avatar = 'http://gravatar.com/avatar/${hasha(authUserData.email)}?d=robohash';
const user = {email:authUserData.email, avatar};
commit('setUser', user);
commit('setToken', authUserData.idToken);
}catch(err){
}
}
};
export const getters = {
posts: state => state.posts,
authenticated: state => !!state.token,
user: state => state.user
};