refactor: enhance security and performance in configuration and API routes

- Update Content Security Policy (CSP) in next.config.ts to avoid `unsafe-eval` in production, improving security against XSS attacks.
- Refactor API routes to enforce admin authentication and session validation, ensuring secure access to sensitive endpoints.
- Optimize analytics data retrieval by using database aggregation instead of loading all records into memory, improving performance and reducing memory usage.
- Implement session token creation and verification for better session management and security across the application.
- Enhance error handling and input validation in various API routes to ensure robustness and prevent potential issues.
This commit is contained in:
2026-01-11 22:44:26 +01:00
parent 9cc03bc475
commit 9072faae43
28 changed files with 433 additions and 288 deletions

View File

@@ -159,14 +159,16 @@ export const projectService = {
prisma.userInteraction.groupBy({
by: ['type'],
where: { projectId },
_count: { _all: true },
})
]);
const analytics: Record<string, number> = { views: pageViews, likes: 0, shares: 0 };
interactions.forEach(interaction => {
if (interaction.type === 'LIKE') analytics.likes = 0;
if (interaction.type === 'SHARE') analytics.shares = 0;
const count = (interaction as unknown as { _count?: { _all?: number } })._count?._all ?? 0;
if (interaction.type === 'LIKE') analytics.likes = count;
if (interaction.type === 'SHARE') analytics.shares = count;
});
return analytics;