-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathhttp.js
More file actions
40 lines (36 loc) · 1.34 KB
/
http.js
File metadata and controls
40 lines (36 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* eslint-disable prefer-arrow-callback */
/* eslint-disable func-names */
/* eslint-disable no-param-reassign */
import Axios from 'axios';
import Vue from 'vue';
import { getAccessToken, getRefreshToken, handleAccessTokenExpiration } from '../auth/tokens';
Axios.defaults.baseURL = process.env.VUE_APP_BACKEND_BASE_URL;
Axios.defaults.headers.common['Content-Type'] = 'application/json';
Axios.defaults.headers.common.Accept = 'application/json';
Axios.interceptors.request.use(async function (config) {
if (config.url === '/auth/refresh' || config.url === '/auth/refresh_revoke') {
config.headers.Authorization = `Bearer ${getRefreshToken()}`;
} else if (config.url === '/auth/access_revoke') {
config.headers.Authorization = `Bearer ${getAccessToken()}`;
} else if (config.accessTokenRequired) {
await handleAccessTokenExpiration();
if (getAccessToken()) {
config.headers.Authorization = `Bearer ${getAccessToken()}`;
} else {
window.location.reload();
return { headers: {}, method: config.method, url: '' };
}
}
if (config.url.search('/profile/images') !== -1) {
config.headers['Content-Type'] = 'multipart/form-data';
}
delete config.accessTokenRequired;
return config;
}, function (error) {
return Promise.reject(error);
});
export default {
install() {
Vue.prototype.$http = Axios;
},
};