mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-10-31 11:08:04 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			32 lines
		
	
	
		
			781 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			32 lines
		
	
	
		
			781 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| import Auth from '../api/auth';
 | |
| 
 | |
| const parseErrorCode = error => Promise.reject(error);
 | |
| 
 | |
| export default axios => {
 | |
|   const { apiHost = '' } = window.chatwootConfig || {};
 | |
|   const wootApi = axios.create({ baseURL: `${apiHost}/` });
 | |
|   // Add Auth Headers to requests if logged in
 | |
|   if (Auth.hasAuthCookie()) {
 | |
|     const {
 | |
|       'access-token': accessToken,
 | |
|       'token-type': tokenType,
 | |
|       client,
 | |
|       expiry,
 | |
|       uid,
 | |
|     } = Auth.getAuthData();
 | |
|     Object.assign(wootApi.defaults.headers.common, {
 | |
|       'access-token': accessToken,
 | |
|       'token-type': tokenType,
 | |
|       client,
 | |
|       expiry,
 | |
|       uid,
 | |
|     });
 | |
|   }
 | |
|   // Response parsing interceptor
 | |
|   wootApi.interceptors.response.use(
 | |
|     response => response,
 | |
|     error => parseErrorCode(error)
 | |
|   );
 | |
|   return wootApi;
 | |
| };
 | 
