feat: get user - #38
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a new authenticated endpoint for retrieving the current user's details (GET /users/me) and implements the necessary JWT-based authentication infrastructure to secure endpoints globally. The implementation follows domain-driven design principles with proper separation between controllers, services, and domain entities.
Key changes:
- Added a global
AuthGuardthat secures all endpoints by default using JWT authentication, with support for marking routes as public - Implemented
GET /users/meendpoint with corresponding service layer and domain method to safely serialize user data - Enhanced test reliability by running Jest tests sequentially
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/application/shared/guards/auth.guard.ts |
Implements JWT authentication guard to protect endpoints globally |
src/application/shared/decorators/payload.decorator.ts |
Provides decorator to extract JWT payload from authenticated requests |
src/app.module.ts |
Registers AuthGuard as a global guard for application-wide authentication |
src/application/users/controllers/get-user.controller.ts |
Adds controller for retrieving authenticated user details with OpenAPI documentation |
src/application/users/services/get-user.service.ts |
Implements service to retrieve user by ID and return sanitized data |
src/domain/users/entities/user.entity.ts |
Adds toJSON method to exclude sensitive fields from serialization |
src/application/users/users.module.ts |
Registers new GetUserController and GetUserService |
tests/integration/application/users/controllers/get-user.controller.test.ts |
Adds integration tests for the new endpoint |
tests/unit/application/users/services/get-user.service.test.ts |
Adds unit tests for GetUserService |
package.json |
Modifies test script to run sequentially for improved reliability |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
This pull request introduces a new authenticated endpoint for retrieving the current user's details and implements supporting infrastructure for authentication using JWT. It also adds corresponding controller, service, and tests, and improves test reliability.
Authentication infrastructure:
AuthGuardusing JWT to secure endpoints by default, with support for public routes via metadata. (src/application/shared/guards/auth.guard.ts,src/app.module.ts) [1] [2] [3]Payloaddecorator to easily access the JWT payload in controllers. (src/application/shared/decorators/payload.decorator.ts)User endpoint and logic:
GET /users/meendpoint viaGetUserControllerto return the currently authenticated user's details, using the newGetUserService. (src/application/users/controllers/get-user.controller.ts,src/application/users/services/get-user.service.ts,src/application/users/users.module.ts) [1] [2] [3] [4]toJSONmethod on theUserentity to exclude sensitive fields like password and tokens from API responses. (src/domain/users/entities/user.entity.ts)Testing improvements:
tests/integration/application/users/controllers/get-user.controller.test.ts,tests/unit/application/users/services/get-user.service.test.ts) [1] [2]Other improvements:
package.json)