diff --git a/auth/auth.class.ts b/auth/auth.class.ts index a3888ce468..58b43478ca 100644 --- a/auth/auth.class.ts +++ b/auth/auth.class.ts @@ -169,11 +169,36 @@ export class Auth { */ static deniedPatients() { return (req, res, next) => { + if (req.user.type !== 'paciente-token') { - next(); + return next(); + } + // Permitir explícitamente algunas rutas aún para pacientes + const allowedForPaciente = [ + '/protocolosLab', + '/historial', + '/prestaciones/huds', + '/prestaciones', + '/recetas', + '/paciente/' + ]; + const requestPath = (req.path || req.url || '').toString(); + // Si la ruta es una de las permitidas, continuar + const idPacientePath = requestPath ? requestPath.split('/').pop() : null; + if (allowedForPaciente.some(p => requestPath.includes(p))) { + const idPacienteQuery = req.query?.pacienteId || req.query?.idPaciente || idPacientePath || null; + const idPacienteToken = req.user.pacientes.find(p => String(p.id) === String(idPacienteQuery)); + + if (idPacienteToken) { + return next(); + } } else { - next(403); + if (requestPath.endsWith('.pdf')) { + return next(); + } } + // Por defecto denegar si no está en las excepciones ni coincide el paciente + return next(403); }; } diff --git a/config.ts b/config.ts index 24199035d7..8a75d27a24 100644 --- a/config.ts +++ b/config.ts @@ -7,13 +7,14 @@ import { IPS } from './config.private'; const appMiddleware = [ Auth.authenticate(), - // Auth.deniedPatients() + Auth.deniedPatients() ]; const mobileMiddleware = [ Auth.authenticate() ]; + /* const publicMiddleware = [ Auth.authenticatePublic()