[LOCKLITE-132] Refactor register and login API routes#72
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the authentication system by separating business errors from HTTP errors, implementing proper use cases for sign-in and registration, and improving API documentation structure. The changes introduce a cleaner separation of concerns and better error handling for authentication flows.
- Separated business errors (with error codes) from generic HTTP errors
- Introduced use cases for authentication operations with proper dependency injection
- Created dedicated DTOs for authentication payloads and responses
- Improved Swagger documentation with consistent tagging
Reviewed Changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/modules/shared/errors/business-error-code.enum.ts | Added USER_ALREADY_EXISTS error code |
| src/modules/shared/dto/output/errors/business.error.dto.ts | New DTO for business errors with error codes |
| src/modules/shared/dto/output/errors/http.error.dto.ts | Removed business error code from generic HTTP errors |
| src/modules/shared/dto/output/responses/abstract/http.response.dto.ts | Updated to include BusinessErrorDto in response union |
| src/modules/shared/dto/output/data/sign-in.data.dto.ts | New DTO for sign-in response data |
| src/modules/shared/dto/output/data/register.data.dto.ts | New DTO for registration response data |
| src/modules/shared/dto/models/user.model.dto.ts | New user model DTO |
| src/modules/shared/dto/input/payloads/register.payload.dto.ts | New registration payload DTO |
| src/modules/api/usecases/auth/signin.usecase.ts | New use case for sign-in logic |
| src/modules/api/usecases/auth/register.usecase.ts | New use case for registration logic |
| src/modules/api/services/hash.service.ts | New service for password hashing operations |
| src/modules/api/repositories/users.repository.ts | New repository for user data operations |
| src/modules/api/errors/business/auth/user-already-exists.error.ts | New business error for duplicate user registration |
| src/modules/api/adapters/user.adapter.ts | New adapter for converting user entities to DTOs |
| src/lib/auth.ts | Refactored to use SignInUseCase instead of direct database calls |
| src/app/api/auth/register/route.ts | Completely refactored to use new architecture |
| Various route files | Updated Swagger documentation tags for consistency |
Comments suppressed due to low confidence (1)
src/modules/api/services/hash.service.ts:29
- The parameter name 'hashedInput' is misleading. This parameter represents the plain text input to be compared against the hashed reference, not a hashed input. Consider renaming it to 'plainTextInput' or 'input' for clarity.
public async compare(
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.