fix: comprehensive security and type improvements from PR #20 review

Security Enhancements:
- Implemented proper rate limiting with automatic cleanup for /register and /forgot-password endpoints
- Added memory usage protection with MAX_ENTRIES limit (10000)
- Fixed rate limiter memory leaks by adding cleanup intervals
- Improved IP extraction with x-real-ip and x-client-ip header support

Code Quality Improvements:
- Refactored ProcessingStatusManager from individual functions to class-based architecture
- Maintained backward compatibility with singleton instance pattern
- Fixed TypeScript strict mode violations across the codebase
- Resolved all build errors and type mismatches

UI Component Fixes:
- Removed unused chart components (Charts.tsx, DonutChart.tsx)
- Fixed calendar component type issues by removing unused custom implementations
- Resolved theme provider type imports
- Fixed confetti component default options handling
- Corrected pointer component coordinate type definitions

Type System Improvements:
- Extended NextAuth types to support dual auth systems (regular and platform users)
- Fixed nullable type handling throughout the codebase
- Resolved Prisma JSON field type compatibility issues
- Corrected SessionMessage and ImportRecord interface definitions
- Fixed ES2015 iteration compatibility issues

Database & Performance:
- Updated database pool configuration for Prisma adapter compatibility
- Fixed pagination response structure in user management endpoints
- Improved error handling with proper error class usage

Testing & Build:
- All TypeScript compilation errors resolved
- ESLint warnings remain but no errors
- Build completes successfully with proper static generation
This commit is contained in:
2025-06-30 19:15:25 +02:00
parent 5042a6c016
commit 38aff21c3a
32 changed files with 1002 additions and 929 deletions

View File

@ -6,8 +6,10 @@ import { prisma } from "./prisma";
// Define the shape of the JWT token
declare module "next-auth/jwt" {
interface JWT {
companyId: string;
role: string;
companyId?: string;
role?: string;
isPlatformUser?: boolean;
platformRole?: string;
}
}
@ -18,8 +20,11 @@ declare module "next-auth" {
id?: string;
name?: string;
email?: string;
image?: string;
companyId?: string;
role?: string;
isPlatformUser?: boolean;
platformRole?: string;
};
}
@ -27,8 +32,10 @@ declare module "next-auth" {
id: string;
email: string;
name?: string;
companyId: string;
role: string;
companyId?: string;
role?: string;
isPlatformUser?: boolean;
platformRole?: string;
}
}
@ -50,13 +57,13 @@ export const authOptions: NextAuthOptions = {
include: { company: true },
});
if (!user || !user.hashedPassword) {
if (!user || !user.password) {
return null;
}
const isPasswordValid = await bcrypt.compare(
credentials.password,
user.hashedPassword
user.password
);
if (!isPasswordValid) {
@ -71,7 +78,7 @@ export const authOptions: NextAuthOptions = {
return {
id: user.id,
email: user.email,
name: user.name,
name: user.name || undefined,
companyId: user.companyId,
role: user.role,
};
@ -98,6 +105,8 @@ export const authOptions: NextAuthOptions = {
if (user) {
token.companyId = user.companyId;
token.role = user.role;
token.isPlatformUser = user.isPlatformUser;
token.platformRole = user.platformRole;
}
return token;
},
@ -105,6 +114,8 @@ export const authOptions: NextAuthOptions = {
if (token && session.user) {
session.user.companyId = token.companyId;
session.user.role = token.role;
session.user.isPlatformUser = token.isPlatformUser;
session.user.platformRole = token.platformRole;
}
return session;
},