Initial Commit

This commit is contained in:
Eric Gullickson
2025-09-17 16:09:15 -05:00
parent 0cdb9803de
commit a052040e3a
373 changed files with 437090 additions and 6773 deletions

View File

@@ -16,10 +16,20 @@ export const apiClient: AxiosInstance = axios.create({
},
});
// Request interceptor for auth token
// Request interceptor for auth token with mobile debugging
apiClient.interceptors.request.use(
async (config: InternalAxiosRequestConfig) => {
// Token will be added by Auth0 wrapper
// Log mobile requests for debugging
if (import.meta.env.MODE === 'development') {
const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
if (isMobile && config.url?.includes('/vehicles')) {
console.log('Mobile API request:', config.method?.toUpperCase(), config.url, {
hasAuth: !!config.headers.Authorization,
authPreview: config.headers.Authorization?.toString().substring(0, 20) + '...'
});
}
}
return config;
},
(error) => {
@@ -27,19 +37,37 @@ apiClient.interceptors.request.use(
}
);
// Response interceptor for error handling
// Response interceptor for error handling with mobile-specific logic
apiClient.interceptors.response.use(
(response) => response,
(error) => {
const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
if (error.response?.status === 401) {
// Handle unauthorized - Auth0 will redirect to login
toast.error('Session expired. Please login again.');
// Enhanced 401 handling for mobile token issues
const errorMessage = error.response?.data?.message || '';
const isTokenIssue = errorMessage.includes('token') || errorMessage.includes('JWT') || errorMessage.includes('Unauthorized');
if (isMobile && isTokenIssue) {
// Mobile devices sometimes have token timing issues
// Show a more helpful message that doesn't sound like a permanent error
toast.error('Refreshing your session...', {
duration: 3000,
id: 'mobile-auth-refresh' // Prevent duplicate toasts
});
} else {
// Standard session expiry message
toast.error('Session expired. Please login again.');
}
} else if (error.response?.status === 403) {
toast.error('You do not have permission to perform this action.');
} else if (error.response?.status >= 500) {
toast.error('Server error. Please try again later.');
} else if (error.code === 'NETWORK_ERROR' && isMobile) {
// Mobile-specific network error handling
toast.error('Network error. Please check your connection and try again.');
}
return Promise.reject(error);
}
);