Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions auth/auth.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}

Expand Down
3 changes: 2 additions & 1 deletion config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading