Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
986 B
1
Indexable
Never
import axios from 'axios';
import { store } from '../redux/store';

const instance = axios.create({
  baseURL: process.env.REACT_APP_BASE_URL,
  // withCredentials: true,
});
instance.interceptors.request.use(
  function (config) {
    const accessToken = store?.getState()?.user?.account?.accessToken;

    const token = `Bearer ${accessToken}`;

    config.headers.authorization = token;

    return config;
  },
  function (error) {
    // Do something with request error
    return Promise.reject(error);
  },
);
instance.interceptors.response.use(
  function (response) {
    // Any status code that lie within the range of 2xx cause this function to trigger
    // Do something with response data
    return response.data;
  },
  function (error) {
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    return Promise.reject(error);
  },
);
export default instance;