mirror of
https://github.com/strapi/strapi.git
synced 2025-07-25 09:56:53 +00:00
parent
c58e169a6b
commit
cf2f87cbb8
@ -1,4 +1,4 @@
|
|||||||
import { axiosInstance } from '../../../../../../admin/admin/src/core/utils';
|
import axiosInstance from '../../../utils/axiosInstance';
|
||||||
|
|
||||||
const fetchEmailSettings = async () => {
|
const fetchEmailSettings = async () => {
|
||||||
const { data } = await axiosInstance.get('/email/settings');
|
const { data } = await axiosInstance.get('/email/settings');
|
||||||
|
36
packages/core/email/admin/src/utils/axiosInstance.js
Normal file
36
packages/core/email/admin/src/utils/axiosInstance.js
Normal 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;
|
Loading…
x
Reference in New Issue
Block a user