Base attempt at using vuex to handle logins

This commit is contained in:
Dane Everitt 2018-06-05 23:00:01 -07:00
parent cc58bc9bd5
commit e948d81d8a
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
12 changed files with 218 additions and 202 deletions

View file

@ -0,0 +1,38 @@
import { User } from './models/user';
export const storeData = {
state: {
user: null,
},
actions: {
login: function ({ commit }) {
commit('login');
},
logout: function ({ commit }) {
commit('logout');
},
},
getters: {
getCurrentUser: function (state) {
if (!(state.user instanceof User)) {
state.user = User.fromJWT(localStorage.getItem('token'));
}
return state.user;
},
},
mutations: {
/**
* Log in a user and store them in vuex using the local storage token.
*
* @param state
*/
login: function (state) {
state.user = User.fromJWT(localStorage.getItem('token'));
},
logout: function (state) {
console.log('logout');
state.user = null;
}
}
};