Repository navigation
31 epic authentication authorization - #54
Merged
Merged
Conversation
Co-authored-by: Copilot <[email protected]>
Use gorm.DeletedAt to exclude soft-deleted users from repository lookups
Use strconv.ParseBool for COOKIE_SECURE config parsing
…d update test for malformed JSON input
feat: implement auth apis
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
fix(e2e): use log-based wait strategy for Postgres container readiness
Scope TESTCONTAINERS_RYUK_DISABLED to Colima sockets only
This reverts commit 75f18d6.
feat: implement e2e tests
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
feat: update login page ui
Co-authored-by: Copilot <[email protected]>
Split `Envelope<T>` into `SuccessEnvelope<T>` / `ApiErrorEnvelope` discriminated union
…e-error-code feat: implement machine-readable error codes and enhance error handli…
…prove state handling
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements an authentication-first flow across the stack: the API shifts to cookie-based auth with refresh-token rotation and machine-readable error codes, while the web app adds authenticated route guards and a real login that calls the API. It also updates infra/docs/CI to match the new routing and E2E testing approach.
Changes:
- API: move routes under
/api/*, switch auth to HttpOnly cookies + refresh-token family rotation, and standardizeerror_codein the JSON envelope. - Web: add authenticated routing (
/_authenticatedlayout,/dashboard), redirect signed-in users away from/, and wire the login form to the real API. - Tooling/ops: add testcontainers-based E2E tests, update CI workflow, and adjust gateway/Docker configs and docs for the new prefixes and auth model.
Reviewed changes
Copilot reviewed 54 out of 55 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| services/api/test/integration/user_test.go | Updates integration tests for /api/v1 paths, username/full_name fields, and error_code assertions. |
| services/api/test/integration/auth_test.go | Refactors fakes to username + refresh store, updates auth paths, and asserts cookies + error_code values. |
| services/api/test/e2e/api_flow_test.go | Adds full-stack E2E flow using testcontainers-go (Postgres/Redis), migrations, and cookie-based auth lifecycle tests. |
| services/api/migrations/000001_init.sql | Updates initial schema to username + full_name and new index naming. |
| services/api/internal/transport/http/router/router.go | Mounts API under /api, moves health to /api/healthz, and versions under /api/v1. |
| services/api/internal/transport/http/presenter/response.go | Adds error_code to envelope and maps domain/api errors to status+code consistently. |
| services/api/internal/transport/http/middleware/validate.go | Routes JSON bind failures through presenter/apierr (BAD_REQUEST + envelope). |
| services/api/internal/transport/http/middleware/authn.go | Auth middleware now supports cookie auth first, then Bearer header fallback, returning coded errors. |
| services/api/internal/transport/http/handler/user_handler_test.go | Updates handler tests for username/full_name and asserts error_code behavior. |
| services/api/internal/transport/http/handler/user_handler.go | Switches user handlers to username/full_name and presenter-based coded error responses. |
| services/api/internal/transport/http/handler/auth_handler_test.go | Updates auth handler tests for cookie token delivery, refresh via cookie, logout family revocation, and error_code assertions. |
| services/api/internal/transport/http/handler/auth_handler.go | Implements cookie-based login/refresh/logout with token cookies, path-scoped refresh cookie, and cookie clearing. |
| services/api/internal/transport/http/dto/user_dto.go | Updates DTOs and response mapping to username/full_name. |
| services/api/internal/transport/http/dto/auth_dto.go | Updates login request to username and retains an empty refresh request type (cookie-based refresh). |
| services/api/internal/service/user/user_service_test.go | Updates service tests for username/full_name and duplicate-username behavior. |
| services/api/internal/service/user/user_service.go | Updates create/update logic for username/full_name and uniqueness checks. |
| services/api/internal/service/auth/auth_service_test.go | Updates auth service tests for username and refresh-token family rotation/reuse scenarios. |
| services/api/internal/service/auth/auth_service.go | Implements refresh-token rotation with reuse detection + family revocation; switches to username-based login. |
| services/api/internal/repository/redis/token_blacklist.go | Removes legacy token blacklist implementation. |
| services/api/internal/repository/redis/refresh_token_store.go | Adds Redis-backed refresh-token rotation store (first-use tracking + family revocation). |
| services/api/internal/repository/postgres/user_repository.go | Updates persistence to username/full_name and uses GORM’s soft-delete mechanism. |
| services/api/internal/platform/token/jwt_manager_test.go | Updates JWT tests for username and familyID claims. |
| services/api/internal/platform/token/jwt_manager.go | Extends token issuance to include username + familyID in claims. |
| services/api/internal/domain/user/service.go | Renames user inputs to username/full_name. |
| services/api/internal/domain/user/repository.go | Renames repository lookup to FindByUsername. |
| services/api/internal/domain/user/errors.go | Renames sentinel error to ErrUsernameTaken. |
| services/api/internal/domain/user/entity.go | Renames entity fields to Username and FullName. |
| services/api/internal/domain/auth/service.go | Updates auth service contract: username login, refresh returns TokenPair, logout by familyID. |
| services/api/internal/domain/auth/errors.go | Adds auth domain sentinel errors (invalid creds, token invalid, session invalidated). |
| services/api/internal/domain/auth/claims.go | Renames Email→Username and adds FamilyID claim. |
| services/api/internal/config/load.go | Adds COOKIE_SECURE and admin credential env loading. |
| services/api/internal/config/config.go | Adds Admin config and CookieSecure setting on Server config. |
| services/api/internal/bootstrap/app.go | Swaps blacklist→refresh store, seeds admin user, and wires CookieConfig into AuthHandler. |
| services/api/internal/apierr/codes.go | Introduces API error codes and apierr.Error type for transport-layer mapping. |
| services/api/go.sum | Adds dependency hashes (notably testcontainers-go and transitive deps). |
| services/api/go.mod | Adds testcontainers-go and related indirect dependencies. |
| services/api/README.md | Removes obsolete redis token_blacklist mention. |
| docs/api/http-design.md | Updates auth/user contract docs for cookie-based auth, username/full_name, and error response shape. |
| deploy/nginx/gateway.conf | Updates proxying to preserve /api prefix and routes auth paths accordingly. |
| deploy/docker-compose.prod.yml | Adds COOKIE_SECURE + admin env vars; injects VITE_API_BASE_URL at build time. |
| deploy/docker-compose.dev.yml | Adds cookie/admin env vars for API; sets VITE_API_BASE_URL to gateway origin. |
| deploy/.env.production.example | Documents PUBLIC_URL, cookie secure flag, and admin credentials. |
| apps/web/src/routes/index.tsx | Adds pre-route redirect for authenticated users and refactors login page UI + server error display. |
| apps/web/src/routes/_authenticated/dashboard/index.tsx | Adds protected /dashboard/ placeholder route. |
| apps/web/src/routes/_authenticated.tsx | Adds pathless authenticated layout route guard using React Query cache. |
| apps/web/src/routes/__root.tsx | Adds router context type to provide QueryClient to route guards. |
| apps/web/src/router.tsx | Provides QueryClient in router context. |
| apps/web/src/routeTree.gen.ts | Updates generated route tree to include authenticated layout and dashboard route. |
| apps/web/src/lib/auth-api.ts | Adds auth API wrapper + currentUserQueryOptions for guards and redirects. |
| apps/web/src/lib/api-error.ts | Adds typed API error envelope + error_code extraction helpers for Axios errors. |
| apps/web/src/index.css | Simplifies background colors to plain white and removes gradients. |
| apps/web/src/hooks/use-login-form.ts | Switches login form to real API call, handles error_code mapping, invalidates me, and navigates on success. |
| apps/web/Dockerfile | Adds build-time injection of VITE_API_BASE_URL for the bundled web client. |
| apps/web/.gitignore | Ignores package-lock.json (bun is used). |
| .github/workflows/api-pr-ci.yml | Separates unit/integration tests from E2E tests; runs E2E via testcontainers-go. |
Comments suppressed due to low confidence (1)
services/api/internal/service/user/user_service.go:39
- User creation currently does a pre-check via FindByUsername, but repo.Create does not translate unique-constraint violations into ErrUsernameTaken. Under concurrent requests (or if the username is created between the check and insert), this can surface as an unhandled repo error (likely a 500) instead of a 409/USER_USERNAME_TAKEN. Consider mapping DB unique-violation errors to userdom.ErrUsernameTaken (either in the repository Create or by wrapping the Create error here).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
Contributor
Contributor
fix: use protocol-qualified port strings in testcontainers MappedPort calls
docs: add /api prefix to all route paths in http-design.md
docs: fix API path prefixes in http-design.md to match /api router mount
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
This pull request introduces authentication-aware routing and login functionality to the web app, refactors the login form to use the real API, and updates the styling and build process for improved maintainability and user experience. The most significant changes are the addition of route guards for authenticated areas, a real login form with error handling, and improvements to the CI workflow and Docker build configuration.
Authentication and Routing Enhancements:
routes/_authenticated.tsx) that guards all nested routes, redirecting unauthenticated users to the login page and using React Query's cache for efficient checks. ([apps/web/src/routes/_authenticated.tsxR1-R24](https://github.com/Paca-AI/paca/pull/54/files#diff-3074eccedf95d43098dfe459af6a3b7ad61a3f6d91a5a248f79671dfc610d9f7R1-R24))/dashboard/route under the authenticated layout, serving as a placeholder for protected content. ([[1]](https://github.com/Paca-AI/paca/pull/54/files#diff-3e707b753c6615d573bfbaacec528c92cc7eeb088a7b5e9aa329ca5c169e24dcR1-R9),[[2]](https://github.com/Paca-AI/paca/pull/54/files#diff-b36b78b098eda9e851a950708304d9af0611985b2a460b6cfaaca9c5e96614c0R12-R99))routes/index.tsx) to redirect authenticated users from/to/dashboard, preventing access to the login page when already signed in. ([apps/web/src/routes/index.tsxL1-R38](https://github.com/Paca-AI/paca/pull/54/files#diff-9a640a8d74a699e96d3eace06461dc8f8396f55a0813e916427bb0bb2f1a4597L1-R38))Login Form and API Integration:
useLoginFormto perform real authentication via the API, handle server error codes, and redirect users upon successful login. (F25fab77L1)api-error.tsmodule to provide machine-readable error codes and helpers for handling API error envelopes. ([apps/web/src/lib/api-error.tsR1-R55](https://github.com/Paca-AI/paca/pull/54/files#diff-d7ab9b221bc0aab554d4b3023f703e88e796c3509a57852ac608eecb25de5adbR1-R55))auth-api.tsto encapsulate authentication API calls and user data fetching with React Query. ([apps/web/src/lib/auth-api.tsR1-R34](https://github.com/Paca-AI/paca/pull/54/files#diff-4a3b66105b29f78e5dadbee84dc7af3f954eca12ea61e915a3539ee461bbe839R1-R34))Styling and Build Improvements:
index.css, removing gradients and setting backgrounds to plain white for a cleaner look. ([[1]](https://github.com/Paca-AI/paca/pull/54/files#diff-70ad657a634ce55957729ff8d1c93f697cc7e3ca2a5cb5fe6b00c90d7d515fcdL14-R29),[[2]](https://github.com/Paca-AI/paca/pull/54/files#diff-70ad657a634ce55957729ff8d1c93f697cc7e3ca2a5cb5fe6b00c90d7d515fcdL170-R170))VITE_API_BASE_URLat build time, supporting environment-specific API endpoints. ([apps/web/DockerfileR13-R17](https://github.com/Paca-AI/paca/pull/54/files#diff-4eb403c1470ca34300aea23c38f170d0e8b3c16932a5af4c99da390622d3db4eR13-R17))CI/CD Workflow Updates:
testcontainers-goinstead of manually defined Docker services. ([[1]](https://github.com/Paca-AI/paca/pull/54/files#diff-f1ebc0c0eb20a9af389affa2ea2464b2f405028fa2eb90dff626b4e7be6244c3L79-R81),[[2]](https://github.com/Paca-AI/paca/pull/54/files#diff-f1ebc0c0eb20a9af389affa2ea2464b2f405028fa2eb90dff626b4e7be6244c3L103-R103),[[3]](https://github.com/Paca-AI/paca/pull/54/files#diff-f1ebc0c0eb20a9af389affa2ea2464b2f405028fa2eb90dff626b4e7be6244c3L113-L169),[[4]](https://github.com/Paca-AI/paca/pull/54/files#diff-f1ebc0c0eb20a9af389affa2ea2464b2f405028fa2eb90dff626b4e7be6244c3L182-R140))Miscellaneous:
package-lock.jsonto.gitignorein the web app to avoid accidental commits of lockfiles. ([apps/web/.gitignoreR14](https://github.com/Paca-AI/paca/pull/54/files#diff-3a40410c8cd32e3860f5d9c6aafc7326d6a771ed4b01742fda42df2d4017871bR14))[[1]](https://github.com/Paca-AI/paca/pull/54/files#diff-e03e2f8a6bd5e23a6d47c8ace30e3d7d3f24f3b6cdc2b8915a65d8f22c3ff20eR2-R10),[[2]](https://github.com/Paca-AI/paca/pull/54/files#diff-9cf47cc915a8ae96883f175e43540fd214a10fa797409a128613573c92b47100L1-R14))These changes lay the groundwork for a secure, user-friendly authentication flow and a more maintainable codebase.