2018-05-28 22:37:09 +00:00
|
|
|
import { User } from './models/user';
|
2018-05-28 19:48:42 +00:00
|
|
|
|
|
|
|
export const storeData = {
|
|
|
|
state: {
|
|
|
|
user: null,
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
login: function ({ commit }) {
|
|
|
|
commit('login');
|
|
|
|
},
|
|
|
|
logout: function ({ commit }) {
|
|
|
|
commit('logout');
|
|
|
|
},
|
|
|
|
},
|
|
|
|
getters: {
|
2018-05-28 22:37:09 +00:00
|
|
|
getCurrentUser: function (state) {
|
|
|
|
if (!(state.user instanceof User)) {
|
|
|
|
state.user = User.fromJWT(localStorage.getItem('token'));
|
|
|
|
}
|
|
|
|
|
2018-05-28 19:48:42 +00:00
|
|
|
return state.user;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
mutations: {
|
2018-05-28 22:37:09 +00:00
|
|
|
/**
|
|
|
|
* Log in a user and store them in vuex using the local storage token.
|
|
|
|
*
|
|
|
|
* @param state
|
|
|
|
*/
|
2018-05-28 19:48:42 +00:00
|
|
|
login: function (state) {
|
2018-05-28 22:37:09 +00:00
|
|
|
state.user = User.fromJWT(localStorage.getItem('token'));
|
2018-05-28 19:48:42 +00:00
|
|
|
},
|
|
|
|
logout: function (state) {
|
2018-05-28 22:37:09 +00:00
|
|
|
console.log('logout');
|
2018-05-28 19:48:42 +00:00
|
|
|
state.user = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|