Refactor login page to work on all parts

This commit is contained in:
Daniel_I_Am 2021-09-02 12:52:37 +02:00
parent 77deb525df
commit 2d5eec9dfe
2 changed files with 11 additions and 7 deletions

View File

@ -11,6 +11,14 @@ window.axios = require('axios');
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
const tokenData = JSON.parse(window.localStorage.getItem('authentication-token'));
if (!!tokenData) {
if (new Date(tokenData.valid_until) > new Date()) {
axios.defaults.headers.common.Authorization = tokenData.token;
}
}
/**
* Echo exposes an expressive API for subscribing to channels and listening
* for events that are broadcast by Laravel. Echo and event broadcasting

View File

@ -48,14 +48,10 @@ export default {
});
},
getCurrentToken() {
if (!!axios.defaults.headers.common.Authorization) {
return axios.defaults.headers.common.Authorization;
}
const tokenData = JSON.parse(window.localStorage.getItem('authentication-token'));
if (window.localStorage.getItem('authentication-token')) {
const tokenData = JSON.parse(window.localStorage.getItem('authentication-token'));
if (moment(tokenData.valid_until) > moment()) {
if (!!tokenData) {
if (new Date(tokenData.valid_until) > new Date()) {
this.tokenId = tokenData.id;
axios.defaults.headers.common.Authorization = tokenData.token;
return tokenData.token;