Files
AnchorOS/scripts/test-login-flow.js
Marco Gallegos 0f3de32899 🚀 FASE 4 COMPLETADO: Comentarios auditables + Calendario funcional + Gestión staff/recursos
 COMENTARIOS AUDITABLES IMPLEMENTADOS:
- 80+ archivos con JSDoc completo para auditoría manual
- APIs críticas con validaciones business/security/performance
- Componentes con reglas de negocio documentadas
- Funciones core con edge cases y validaciones

 CALENDARIO MULTI-COLUMNA FUNCIONAL (95%):
- Drag & drop con reprogramación automática
- Filtros por sucursal/staff, tiempo real
- Indicadores de conflictos y disponibilidad
- APIs completas con validaciones de colisión

 GESTIÓN OPERATIVA COMPLETA:
- CRUD staff: APIs + componente con validaciones
- CRUD recursos: APIs + componente con disponibilidad
- Autenticación completa con middleware seguro
- Auditoría completa en todas las operaciones

 DOCUMENTACIÓN ACTUALIZADA:
- TASKS.md: FASE 4 95% completado
- README.md: Estado actual y funcionalidades
- API.md: 40+ endpoints documentados

 SEGURIDAD Y VALIDACIONES:
- RLS policies documentadas en comentarios
- Business rules validadas manualmente
- Performance optimizations anotadas
- Error handling completo

Próximos: Nómina/POS/CRM avanzado (FASE 4 final)
2026-01-17 15:31:13 -06:00

86 lines
3.0 KiB
JavaScript
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.
/**
* Test Login Flow Script
*
* This script tests the login flow to verify the RLS policy fix works
*/
const { createClient } = require('@supabase/supabase-js');
require('dotenv').config();
const SUPABASE_URL = process.env.NEXT_PUBLIC_SUPABASE_URL;
const SUPABASE_ANON_KEY = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY);
async function testLoginFlow() {
console.log('🧪 Testing Login Flow...\n');
try {
// 1. Test sign in with admin credentials
console.log('1⃣ Testing sign in...');
const { data: { user }, error: signInError } = await supabase.auth.signInWithPassword({
email: 'marco.gallegos@anchor23.mx',
password: 'Marco123456!'
});
if (signInError) {
console.error('❌ Sign in failed:', signInError);
return;
}
console.log('✅ Sign in successful!');
console.log(` Email: ${user.email}`);
console.log(` User ID: ${user.id}\n`);
// 2. Test querying staff table (this is what middleware does)
console.log('2⃣ Testing staff query (middleware simulation)...');
const { data: staff, error: staffError } = await supabase
.from('staff')
.select('*')
.eq('user_id', user.id)
.single();
if (staffError) {
console.error('❌ Staff query failed:', staffError);
console.log(' This is the RLS policy issue!');
return;
}
console.log('✅ Staff query successful!');
console.log(` Name: ${staff.display_name}`);
console.log(` Role: ${staff.role}`);
console.log(` Location: ${staff.location_id}\n`);
// 3. Test getting dashboard data
console.log('3⃣ Testing dashboard API...');
const { data: sessionData } = await supabase.auth.getSession();
// Test redirect by checking if we can access the dashboard page
console.log('3⃣ Testing redirect to dashboard page...');
const dashboardResponse = await fetch('http://localhost:2311/aperture', {
headers: {
'Authorization': `Bearer ${sessionData.session.access_token}`
}
});
if (!dashboardResponse.ok) {
console.error('❌ Dashboard API failed:', dashboardResponse.status);
console.log(' Response:', await dashboardResponse.text());
return;
}
const dashboardData = await dashboardResponse.json();
console.log('✅ Dashboard API successful!');
console.log(` KPI Cards: ${dashboardData.kpi_cards ? '✅' : '❌'}`);
console.log(` Top Performers: ${dashboardData.top_performers ? '✅' : '❌'}`);
console.log(` Activity Feed: ${dashboardData.activity_feed ? '✅' : '❌'}\n`);
console.log('🎉 All tests passed! Login flow is working!\n');
} catch (error) {
console.error('❌ Unexpected error:', error);
}
}
testLoginFlow();