mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
32 lines
896 B
TypeScript
32 lines
896 B
TypeScript
import axios from 'axios';
|
|
|
|
import {
|
|
getAuthToken,
|
|
getMfaTempToken,
|
|
getSignupTempToken} from '@app/reactQuery';
|
|
|
|
export const apiRequest = axios.create({
|
|
baseURL: '/',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
});
|
|
|
|
apiRequest.interceptors.request.use((config) => {
|
|
const signupTempToken = getSignupTempToken();
|
|
const mfaTempToken = getMfaTempToken();
|
|
const token = getAuthToken();
|
|
|
|
if (signupTempToken && config.headers) {
|
|
// eslint-disable-next-line no-param-reassign
|
|
config.headers.Authorization = `Bearer ${signupTempToken}`;
|
|
} else if (mfaTempToken && config.headers) {
|
|
// eslint-disable-next-line no-param-reassign
|
|
config.headers.Authorization = `Bearer ${mfaTempToken}`;
|
|
} else if (token && config.headers) {
|
|
// eslint-disable-next-line no-param-reassign
|
|
config.headers.Authorization = `Bearer ${token}`;
|
|
}
|
|
return config;
|
|
});
|