misc_pterodactyl-panel/resources/assets/scripts/_store.js

39 lines
923 B
JavaScript
Raw Normal View History

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: {
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: {
/**
* 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) {
state.user = User.fromJWT(localStorage.getItem('token'));
2018-05-28 19:48:42 +00:00
},
logout: function (state) {
console.log('logout');
2018-05-28 19:48:42 +00:00
state.user = null;
}
}
};