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'; 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 * Echo exposes an expressive API for subscribing to channels and listening
* for events that are broadcast by Laravel. Echo and event broadcasting * for events that are broadcast by Laravel. Echo and event broadcasting

View File

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