feat: implement user authentication and login modal, refactor backend

This commit is contained in:
Omar Sánchez Pizarro
2026-01-20 00:39:28 +01:00
parent 9a61f16959
commit e99424c9ba
29 changed files with 3061 additions and 855 deletions

View File

@@ -0,0 +1,30 @@
import { getRateLimiter } from '../services/redis.js';
// Rate Limiter Middleware
export async function rateLimitMiddleware(req, res, next) {
const rateLimiter = getRateLimiter();
if (!rateLimiter) {
// Si no hay rate limiter configurado, continuar sin límite
return next();
}
try {
// Usar IP como clave para el rate limiting
const key = req.ip || req.socket.remoteAddress || 'unknown';
await rateLimiter.consume(key);
next();
} catch (rejRes) {
// Se excedió el límite de peticiones
const retryAfter = Math.round(rejRes.msBeforeNext / 1000) || 60;
res.set('Retry-After', String(retryAfter));
res.set('X-RateLimit-Limit', '100');
res.set('X-RateLimit-Remaining', '0');
res.status(429).json({
error: 'Too Many Requests',
message: `Has excedido el límite de peticiones. Intenta de nuevo en ${retryAfter} segundos.`,
retryAfter
});
}
}