refactor: Remove console logs and warnings from authentication and API handling

This commit is contained in:
2025-11-02 13:53:29 -06:00
parent 886a3aeab3
commit 19472b840c
9 changed files with 8 additions and 77 deletions

View File

@@ -38,13 +38,10 @@ async function refreshToken(): Promise<string | null> {
const refreshTokenValue = localStorage.getItem('refresh_token');
if (!refreshTokenValue) {
console.warn('🔄 No refresh token available');
return null;
}
try {
console.log('🔄 [API] Intentando refrescar token...');
const response = await fetch(`${API_BASE_URL}/v1/auth/refresh`, {
method: 'POST',
headers: {
@@ -75,7 +72,6 @@ async function refreshToken(): Promise<string | null> {
// Guardar los nuevos tokens
if (data.access_token) {
console.log('✅ [API] Token refrescado exitosamente');
localStorage.setItem('access_token', data.access_token);
if (data.refresh_token) {
@@ -147,8 +143,6 @@ async function fetchApi<T = any>(
// Si recibimos 401 o 403 y no es el endpoint de refresh, intentar refrescar el token
if ((response.status === 401 || response.status === 403) && !endpoint.includes('/auth/refresh') && retryCount === 0) {
console.warn(`⚠️ [API] ${response.status} recibido en ${endpoint}, intentando refrescar token...`);
console.log(`⚠️ [API] Token actual disponible:`, token ? 'Sí (parcial: ' + token.substring(0, 20) + '...)' : 'No');
isRefreshing = true;
try {
@@ -156,13 +150,11 @@ async function fetchApi<T = any>(
if (newToken) {
// Token refrescado exitosamente
console.log(`✅ [API] Reintentando petición a ${endpoint} con nuevo token`);
onTokenRefreshed(newToken);
isRefreshing = false;
// Reintentar la petición original con el nuevo token
return await fetchApi<T>(endpoint, options, 1);
} else {
console.error(`❌ [API] No se pudo refrescar el token para ${endpoint}`);
isRefreshing = false;
// Retornar error 401 para que la capa superior lo maneje
return {
@@ -171,7 +163,6 @@ async function fetchApi<T = any>(
};
}
} catch (refreshError) {
console.error(`❌ [API] Error al refrescar token:`, refreshError);
isRefreshing = false;
return {
error: 'Error al refrescar la sesión',