Skip to content

31 epic authentication authorization - #54

Merged
pikann merged 52 commits into
masterfrom
31-epic-authentication-authorization
Mar 25, 2026
Merged

pikann merged 52 commits into
masterfrom
31-epic-authentication-authorization

Conversation

@pikann

@pikann pikann commented Mar 25, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • Added a pathless layout route (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))
  • Introduced a /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))
  • Updated the root route (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:

  • Refactored useLoginForm to perform real authentication via the API, handle server error codes, and redirect users upon successful login. (F25fab77L1)
  • Added a new api-error.ts module 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))
  • Implemented auth-api.ts to 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:

  • Simplified the default background colors in 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))
  • Updated the Dockerfile to inject VITE_API_BASE_URL at 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:

  • Revised the GitHub Actions workflow to separate unit/integration tests from E2E tests, with E2E tests now managed via testcontainers-go instead 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:

  • Added package-lock.json to .gitignore in the web app to avoid accidental commits of lockfiles. ([apps/web/.gitignoreR14](https://github.com/Paca-AI/paca/pull/54/files#diff-3a40410c8cd32e3860f5d9c6aafc7326d6a771ed4b01742fda42df2d4017871bR14))
  • Updated the router to use context for the React Query client, enabling query usage in route guards. ([[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.

pikann and others added 30 commits March 25, 2026 11:20
Use gorm.DeletedAt to exclude soft-deleted users from repository lookups
Use strconv.ParseBool for COOKIE_SECURE config parsing
fix(e2e): use log-based wait strategy for Postgres container readiness
Scope TESTCONTAINERS_RYUK_DISABLED to Colima sockets only
@pikann pikann linked an issue Mar 25, 2026 that may be closed by this pull request

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 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 standardize error_code in the JSON envelope.
  • Web: add authenticated routing (/_authenticated layout, /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.

Comment thread services/api/test/e2e/api_flow_test.go Resolved
Comment thread services/api/test/e2e/api_flow_test.go Resolved
Comment thread docs/api/http-design.md Resolved
Comment thread docs/api/http-design.md Resolved

Copilot AI commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

@pikann I've opened a new pull request, #55, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

@pikann I've opened a new pull request, #56, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

@pikann I've opened a new pull request, #57, to work on those changes. Once the pull request is ready, I'll request review from you.

@pikann
pikann merged commit 918c8a1 into master Mar 25, 2026
5 checks passed
@pikann
pikann deleted the 31-epic-authentication-authorization branch March 25, 2026 14:23
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.

[Epic] Authentication & Authorization

3 participants