Add debug logging for markContactEmailsAsRead and remove password change restriction
This commit is contained in:
@@ -57,34 +57,3 @@ export const authenticate = async (req, res, next) => {
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Optional authentication - nepovinnné overenie
|
||||
* Ak je token poskytnutý, overí ho, ale nehodí error ak nie je
|
||||
*/
|
||||
export const optionalAuthenticate = async (req, res, next) => {
|
||||
try {
|
||||
let token = null;
|
||||
|
||||
const authHeader = req.headers.authorization;
|
||||
if (authHeader && authHeader.startsWith('Bearer ')) {
|
||||
token = authHeader.substring(7);
|
||||
}
|
||||
|
||||
if (!token && req.cookies && req.cookies.accessToken) {
|
||||
token = req.cookies.accessToken;
|
||||
}
|
||||
|
||||
if (token) {
|
||||
const decoded = verifyAccessToken(token);
|
||||
const user = await getUserById(decoded.id);
|
||||
req.user = user;
|
||||
req.userId = user.id;
|
||||
}
|
||||
|
||||
next();
|
||||
} catch (error) {
|
||||
// Ignoruj chyby, len pokračuj bez user objektu
|
||||
next();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { logger } from '../../utils/logger.js';
|
||||
|
||||
export function validateBody(req, res, next) {
|
||||
const data = JSON.stringify({ body: req.body, query: req.query, params: req.params });
|
||||
const dangerousPatterns = [
|
||||
@@ -10,8 +12,8 @@ export function validateBody(req, res, next) {
|
||||
];
|
||||
for (const pattern of dangerousPatterns) {
|
||||
if (pattern.test(data)) {
|
||||
console.warn(`❌ Suspicious input detected: ${data}`);
|
||||
return res.status(400).json({ message: '🚨 Malicious content detected in request data' });
|
||||
logger.warn('Suspicious input detected', { data: data.substring(0, 100) });
|
||||
return res.status(400).json({ message: 'Malicious content detected in request data' });
|
||||
}
|
||||
}
|
||||
next();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { ZodError } from 'zod';
|
||||
import { ValidationError } from '../../utils/errors.js';
|
||||
import { logger } from '../../utils/logger.js';
|
||||
|
||||
/**
|
||||
* Middleware na validáciu request body pomocou Zod schema
|
||||
@@ -34,7 +35,7 @@ export const validateBody = (schema) => {
|
||||
}
|
||||
|
||||
// Log unexpected errors
|
||||
console.error('Validation error:', error);
|
||||
logger.error('Validation error', { error: error.message });
|
||||
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
@@ -74,7 +75,7 @@ export const validateQuery = (schema) => {
|
||||
});
|
||||
}
|
||||
|
||||
console.error('Query validation error:', error);
|
||||
logger.error('Query validation error', { error: error.message });
|
||||
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
@@ -114,7 +115,7 @@ export const validateParams = (schema) => {
|
||||
});
|
||||
}
|
||||
|
||||
console.error('Params validation error:', error);
|
||||
logger.error('Params validation error', { error: error.message });
|
||||
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
|
||||
Reference in New Issue
Block a user