blob: 843a2586cfb35590273aae4bb48f8b0379b78e5b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
export default function({ $axios, store }) {
$axios.setHeader('accept', 'application/vnd.lolisafe.json');
$axios.onRequest(config => {
if (store.state.token) {
config.headers.common['Authorization'] = `bearer ${store.state.token}`;
}
});
$axios.onError(error => {
if (process.env.development) console.error('[AXIOS Error]', error);
if (process.browser) {
store.dispatch('alert', {
text: error.response.data.message,
error: true
});
if (error.response.data.message.indexOf('Token expired') !== -1) {
store.dispatch('logout');
}
}
});
}
|