Signed-off-by: soupette <cyril@strapi.io>
This commit is contained in:
soupette 2021-12-28 13:42:33 +01:00
parent c58e169a6b
commit cf2f87cbb8
2 changed files with 37 additions and 1 deletions

View File

@ -1,4 +1,4 @@
import { axiosInstance } from '../../../../../../admin/admin/src/core/utils';
import axiosInstance from '../../../utils/axiosInstance';
const fetchEmailSettings = async () => {
const { data } = await axiosInstance.get('/email/settings');

View File

@ -0,0 +1,36 @@
import axios from 'axios';
import { auth } from '@strapi/helper-plugin';
const instance = axios.create({
baseURL: process.env.STRAPI_ADMIN_BACKEND_URL,
});
instance.interceptors.request.use(
async config => {
config.headers = {
Authorization: `Bearer ${auth.getToken()}`,
Accept: 'application/json',
'Content-Type': 'application/json',
};
return config;
},
error => {
Promise.reject(error);
}
);
instance.interceptors.response.use(
response => response,
error => {
// whatever you want to do with the error
if (error.response?.status === 401) {
auth.clearAppStorage();
window.location.reload();
}
throw error;
}
);
export default instance;