Skip to content

feat: user login - #37

Merged
daniloamsilva merged 5 commits into
dddfrom
feat/user-login
Dec 14, 2025
Merged

daniloamsilva merged 5 commits into
dddfrom
feat/user-login

Conversation

@daniloamsilva

Copy link
Copy Markdown
Owner

This pull request introduces a user authentication (login) feature and refactors user creation DTOs for improved clarity and consistency. The main changes include the implementation of the login endpoint, supporting DTOs and services, and comprehensive tests for the new functionality. Additionally, the user creation flow now uses a more descriptive DTO name.

Authentication Feature Implementation:

  • Added a new LoginController with a /login endpoint, allowing users to authenticate with their email and password. The controller uses a new LoginService to handle authentication logic and returns a JWT access token upon successful login. [1] [2]
  • Introduced LoginRequestDto and LoginResponseDto to clearly define the expected request and response structures for the login endpoint. [1] [2]
  • Registered JwtModule globally in users.module.ts to support JWT operations for authentication.

User Creation Refactor:

  • Renamed CreateUserDto to CreateUserRequestDto throughout the codebase for better clarity and consistency in DTO naming. [1] [2] [3] [4] [5]

Testing Enhancements:

  • Added integration tests for the login controller, covering successful login, invalid credentials, and validation errors.
  • Added unit tests for the login service to ensure correct authentication logic and error handling.

Domain Model Update:

  • Added a validatePassword method to the User entity to encapsulate password validation logic.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request implements a user login/authentication feature using JWT tokens and refactors user creation DTOs for improved naming consistency. The implementation follows the existing codebase patterns with a clean separation between API layer (controllers), application layer (use-cases/services), and domain layer (entities), along with comprehensive test coverage.

Key Changes:

  • Added JWT-based login functionality with /login endpoint that authenticates users via email/password and returns access tokens
  • Refactored DTO naming from CreateUserDto to CreateUserRequestDto for consistency with new LoginRequestDto pattern
  • Enhanced User entity with validatePassword method to encapsulate password validation logic

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/api/users/controllers/login.controller.ts New controller exposing POST /login endpoint with OpenAPI documentation
src/api/users/users.module.ts Configured JwtModule with global registration and added LoginController/LoginService providers
src/application/users/use-cases/login.service.ts Core authentication logic validating credentials and generating JWT tokens
src/application/users/dtos/login-request.dto.ts Request DTO with validation for email/password login fields
src/application/users/dtos/login-response.dto.ts Response DTO defining login success structure with access token
src/domain/users/entities/user.entity.ts Added validatePassword method delegating to Password value object
src/application/users/dtos/create-user-request.dto.ts Renamed from CreateUserDto for naming consistency
src/application/users/use-cases/create-user.service.ts Updated import to use renamed CreateUserRequestDto
src/api/users/controllers/create-user.controller.ts Updated import to use renamed CreateUserRequestDto
tests/unit/application/users/use-cases/login.service.test.ts Unit tests covering login success, invalid credentials, and non-existent user scenarios
tests/integration/api/users/controllers/login.controller.test.ts Integration tests validating API behavior including validation errors and authentication flows

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/application/users/dtos/login-response.dto.ts
Comment thread tests/integration/api/users/controllers/login.controller.test.ts Outdated
Comment thread src/api/users/users.module.ts
Comment thread src/application/users/use-cases/login.service.ts Outdated
Comment thread src/application/users/use-cases/login.service.ts
Comment thread src/application/users/dtos/login-request.dto.ts
@daniloamsilva
daniloamsilva merged commit 7a5032f into ddd Dec 14, 2025
2 of 4 checks passed
@daniloamsilva
daniloamsilva deleted the feat/user-login branch December 14, 2025 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants