misc_pterodactyl-panel/resources/assets/scripts/store/modules/user.js

35 lines
777 B
JavaScript
Raw Normal View History

2018-06-03 22:45:01 +00:00
import {User} from "../../models/user";
export const userModule = {
state: {
user: null,
},
actions: {
login ({ commit }) {
commit('setUser', User.fromJWT(localStorage.getItem('token')));
},
logout ({ commit }) {
commit('unsetUser');
}
},
getters: {
getCurrentUser: function (state) {
return state.user;
},
},
mutations: {
/**
* Log in a user and store them in vuex using the local storage token.
*
* @param state
* @param user
*/
setUser: function (state, user) {
state.user = user;
},
unsetUser: function (state) {
state.user = null;
}
}
};