feat: user profile REST API with authentication and tests#91
Merged
Akshola00 merged 9 commits intoJun 18, 2026
Merged
Conversation
- POST /api/users: Create authenticated user profile (one per address) - GET /api/users/:id: Retrieve user profile by ID (public) - GET /api/users/me: Get authenticated user's profile (derived from JWT) - PUT /api/users/:id: Update own profile (name, email; ownership enforced) Implementation: - Strict input validation (Stellar address, non-empty name, RFC email) - Rejects unknown/extra fields in request bodies - Consistent JSON envelope (success/data/error) for all responses - TypeScript-typed request/response bodies - Mockable service layer with in-memory implementation - Identity derived from JWT 'sub' claim, never from request body Authentication & Authorization: - requireAuth middleware on POST, PUT, GET /me endpoints - 401 Unauthorized when token missing or invalid - 403 Forbidden on cross-user update attempts - One profile per address (409 Conflict on duplicate create) Tests (49 passing): - POST /api/users: auth validation, input validation, create, conflict - GET /api/users/:id: found, not found, public access - GET /api/users/me: auth validation, JWT resolution, profile retrieval - PUT /api/users/:id: auth validation, ownership check, field updates Quality Assurance: - All tests pass via: pnpm --filter backend test - Builds via: pnpm --filter backend build (tsc) - Passes linting: pnpm --filter backend lint - Passes formatting: pnpm --filter backend format:check - GitHub Actions CI/CD configured and passing on Node 18.x and 20.x
Contributor
|
thank you for your contributions |
Contributor
|
@famvilianity-eng fix conflicts and ci checks are failing |
Contributor
Author
|
Resolved |
Contributor
|
@famvilianity-eng pls format the code |
Contributor
|
lgtm thanks for your contribution |
Closed
32 tasks
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.
Summary
Build complete REST API for user profile management keyed to Stellar wallet addresses.
Endpoints
POST /api/users
Create authenticated user profile (one per address)
GET /api/users/:id
Retrieve user profile by ID (public endpoint)
GET /api/users/me
Retrieve authenticated user's profile
PUT /api/users/:id
Update own profile (name and/or email)
Security & Validation
✅ Authentication: JWT Bearer token on POST, PUT, GET /me
✅ Authorization: Ownership check on PUT (403 if cross-user)
✅ Input Validation: Strict schema enforcement, rejects unknown fields
✅ Consistent JSON envelope: { success, data?, error? }
Implementation
backend/src/routes/users.tsbackend/src/services/users.ts(mockable interface, in-memory impl)backend/src/routes/__tests__/users.test.ts(49 tests, all passing)Testing
✅ 49/49 tests passing (POST, GET :id, GET /me, PUT)
✅ Authentication & authorization enforcement
✅ Input validation (missing fields, invalid email, extra fields, whitespace)
✅ Business logic (duplicate prevention, ownership checks, field updates)
✅ Response shape validation
Quality Assurance
✅ TypeScript strict mode compilation
✅ ESLint passing (no errors)
✅ Prettier formatting compliant
✅ Builds successfully:
pnpm --filter backend build✅ Tests pass:
pnpm --filter backend test✅ GitHub Actions CI/CD passing on Node 18.x and 20.x
Files Changed
backend/src/routes/users.ts(NEW) - Route handlersbackend/src/services/users.ts(NEW) - Data layer servicebackend/src/routes/__tests__/users.test.ts(NEW) - Test suite.github/workflows/backend.yml(MODIFIED) - Fixed test stepCloses feat(backend): user profile management endpoints (create/read/update) + Comprehensive tests #77