26 lines
812 B
TypeScript
26 lines
812 B
TypeScript
|
import axios from 'axios';
|
||
|
import { ActionTree } from 'vuex';
|
||
|
import { StateInterface } from '../index';
|
||
|
import { UserStateInterface } from './state';
|
||
|
|
||
|
const actions: ActionTree<UserStateInterface, StateInterface> = {
|
||
|
login ({ commit }, payload): any {
|
||
|
axios.post("/auth", {
|
||
|
userid: payload.userid,
|
||
|
password: payload.password
|
||
|
}).then(function (response) {
|
||
|
let token = (<UserStateInterface>response.data).token;
|
||
|
console.log(token);
|
||
|
if (token)
|
||
|
token.expires = new Date(token.expires);
|
||
|
commit('setUser', (<UserStateInterface>response.data).user);
|
||
|
commit('setToken', token);
|
||
|
commit('setPermissions', (<UserStateInterface>response.data).permissions);
|
||
|
}).catch(function (error) {
|
||
|
console.error(error);
|
||
|
});
|
||
|
}
|
||
|
};
|
||
|
|
||
|
export default actions;
|