login: ({ commit, dispatch }, data) =>
new Promise((resolve, reject) => {
apiClient
.post('/auth', data)
.then(resp => {
const { access_token: token, expiryDate } = resp.data;
localStorage.setItem('access_token', token);
apiClient.defaultConfig.headers.Authorization = `Bearer ${token}`;
commit('login', token);
dispatch('getUserInfo');
.....
resolve(resp);
})
.catch(err => {
localStorage.removeItem('access_token');
console.error(err);
reject(err);
});
})
{
login: String,
password: String,
remember: Boolean
}
{
access_token: ...,
expiryDate: YYYY-MM-DD hh:ii:ss
}
if (new Date(expiryDate) >= new Date()) удалить токен...