[LOCKLITE-109] Create an Auth Guard in API#76
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR introduces authentication guard functionality to the API by modifying the handleApiRequest function to support optional authentication checks. The changes enable endpoints to specify whether they require authentication, automatically validating JWT tokens and sessions when needed.
- Refactored
handleApiRequestto accept an object with authentication requirements - Created a new
UnauthorizedErrorclass for consistent error handling - Updated API routes to specify their authentication requirements and include 401 response documentation
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/modules/api/helpers/api/handle-api-request.ts |
Refactored to support authentication checks with JWT token and session validation |
src/modules/api/errors/http/unauthorized.error.ts |
Added new error class for unauthorized access scenarios |
src/app/api/vaults/route.ts |
Updated to require authentication and added 401 response documentation |
src/app/api/vaults/[id]/route.ts |
Updated to require authentication and added 401 response documentation |
src/app/api/auth/register/route.ts |
Updated to explicitly not require authentication |
|
TODO : improve coverage |
|
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | |
|---|---|---|---|---|---|
| 19693650 | Triggered | Generic Password | 79233dd | tests/units/modules/api/usecases/auth/signin.usecase.test.ts | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secret safely. Learn here the best practices.
- Revoke and rotate this secret.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
No description provided.