codigo0/admin-panel/DIAGNOSTICO.md

131 lines
3.8 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 🔍 Diagnóstico del Panel de Administración
## Pasos para diagnosticar el problema
### 1. Abre la consola del navegador
- Presiona `F12` o `Ctrl+Shift+I`
- Ve a la pestaña **Console**
### 2. Ejecuta este código en la consola:
```javascript
// Diagnóstico completo
(async () => {
console.log('🔍 DIAGNÓSTICO DEL PANEL DE ADMINISTRACIÓN\n');
// 1. Verificar token
const token = localStorage.getItem('admin_token');
console.log('1⃣ Token en localStorage:', token ? token.substring(0, 30) + '...' : '❌ NO HAY TOKEN');
// 2. Verificar usuario
const user = localStorage.getItem('admin_user');
console.log('2⃣ Usuario en localStorage:', user ? JSON.parse(user).email : '❌ NO HAY USUARIO');
// 3. Probar endpoint de stats
const API_URL = 'http://localhost:3000';
try {
const statsResponse = await fetch(`${API_URL}/api/stats/content`, {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
}
});
console.log('\n3⃣ Respuesta de /api/stats/content:');
console.log(' Status:', statsResponse.status);
if (statsResponse.ok) {
const data = await statsResponse.json();
console.log(' ✅ Datos recibidos:');
console.log(' Protocolos:', data.protocols);
console.log(' Guías:', data.guides);
console.log(' Fármacos:', data.drugs);
console.log(' Checklists:', data.checklists);
} else {
const error = await statsResponse.json();
console.log(' ❌ Error:', error);
}
} catch (err) {
console.log(' ❌ Error de red:', err.message);
}
// 4. Probar endpoint de content
try {
const contentResponse = await fetch(`${API_URL}/api/content`, {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
}
});
console.log('\n4⃣ Respuesta de /api/content:');
console.log(' Status:', contentResponse.status);
if (contentResponse.ok) {
const data = await contentResponse.json();
console.log(' ✅ Datos recibidos:');
console.log(' Total items:', data.total);
console.log(' Items en página:', data.items?.length || 0);
} else {
const error = await contentResponse.json();
console.log(' ❌ Error:', error);
}
} catch (err) {
console.log(' ❌ Error de red:', err.message);
}
// 5. Verificar backend
try {
const healthResponse = await fetch(`${API_URL}/health`);
const health = await healthResponse.json();
console.log('\n5⃣ Estado del backend:');
console.log(' Status:', health.status);
console.log(' Database:', health.database);
} catch (err) {
console.log(' ❌ Backend no responde:', err.message);
}
console.log('\n✅ Diagnóstico completo');
})();
```
### 3. Copia y pega el resultado aquí
### 4. Si el token no existe o está expirado:
Ejecuta esto para hacer login:
```javascript
(async () => {
const API_URL = 'http://localhost:3000';
try {
const response = await fetch(`${API_URL}/api/auth/login`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: 'admin@emerges-tes.local',
password: 'Admin123!'
})
});
if (response.ok) {
const data = await response.json();
localStorage.setItem('admin_token', data.token);
localStorage.setItem('admin_user', JSON.stringify(data.user));
console.log('✅ Login exitoso');
console.log('Usuario:', data.user.email);
console.log('Token guardado');
location.reload(); // Recargar página
} else {
const error = await response.json();
console.error('❌ Error de login:', error);
}
} catch (err) {
console.error('❌ Error de red:', err);
}
})();
```