-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
ISSUE_NUMBER: GH-6
Description
The checkAuth middleware in src/middleware/checkAuth.ts lacks proper error handling for JWT verification and user lookup.
File: repositories/chatgptapi/src/middleware/checkAuth.ts
Line: 40
Severity: high
Current Behavior
The jwt.verify function and User.findById can throw unhandled exceptions if the token is invalid or the user does not exist.
Expected Behavior
The middleware should gracefully handle errors and return appropriate error responses.
Suggested Fix
Add try-catch blocks to handle JWT verification errors and user lookup errors.
Code Context
const decoded = jwt.verify(token, secret) as JwtPayload;
req.user = await User.findById(decoded.id);Additional Notes
This affects application stability and could expose sensitive information.
Reactions are currently unavailable