import { BASE_HEADER } from "Constants/Config.json" ; import { BASE_URL } from "Constants/constants" ; import axios , { AxiosRequestConfig } from "axios" ; export interface hasToken { hasToken ? : boolean ; } const RequestApi = ( p , condition = { hasToken : false } ) => { let accessToken = null ; let refreshToken = null ; if ( condition . hasToken ) { accessToken = localStorage . getItem ( "themoment_token" ) ; refreshToken = localStorage . getItem ( "themoment_token_refresh" ) ; } try { let header = Object . assign ( BASE_HEADER , p . headers ) ; if ( accessToken ) { header = Object . assign ( header , { Authorization : accessToken , RefreshToken : refreshToken , } ) ; } const res = axios ( { method : p . method , baseURL : BASE_URL , url : p . url , data : p . data , headers : header , } ) ; return res ; } catch ( error ) { throw error ; } } ; export default RequestApi ;