Skip to content

feat: implement auth apis - #44

Merged
pikann merged 11 commits into
31-epic-authentication-authorizationfrom
feature/implement-auth-apis
Mar 25, 2026
Merged

pikann merged 11 commits into
31-epic-authentication-authorizationfrom
feature/implement-auth-apis

Conversation

@pikann

@pikann pikann commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

Summary

This pull request introduces several significant changes to align the authentication and user model with the updated database schema, enhances security by seeding a default admin account, and updates configuration and documentation to reflect these improvements. The main themes are: migration from email to username-based authentication, introduction of secure cookie-based auth flows, and improved admin account management.

Key changes:

Authentication and User Model Alignment

  • Migrated all authentication and user identification from email to username, and from name to full_name in both code and documentation. All relevant structs, interfaces, and database interactions now use username and full_name fields, and JWT claims now carry username instead of email. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12]

  • Updated the authentication flow to use HttpOnly cookies for access and refresh tokens. The login, refresh, and logout endpoints now set and clear cookies instead of returning tokens in the response body. Documentation and handler code have been updated accordingly. [1] [2] [3] [4] [5] [6]

Admin Account Seeding and Configuration

  • Added logic to seed a default admin account on first startup using credentials provided via environment variables. The admin account is only created if it does not already exist. [1] [2] [3] [4] [5] [6]

  • Introduced new environment variables and configuration options for cookie security (COOKIE_SECURE) and admin credentials (ADMIN_USERNAME, ADMIN_PASSWORD). These are now required and validated at startup. [1] [2] [3] [4]

Documentation Updates

  • Revised the API documentation to match the new authentication model (username/password, cookie-based tokens) and user schema (username, full_name). All request/response examples and endpoint descriptions have been updated for clarity and accuracy. [1] [2] [3] [4] [5] [6] [7] [8] [9]

Security and Token Management

  • Enhanced JWT token management by including a FamilyID in claims, supporting refresh token rotation and session family revocation for improved security. [1] [2] [3] [4] [5]

These changes provide a more secure, maintainable, and consistent authentication system and lay the groundwork for future feature development.

Type of Change

  • Documentation
  • Repository structure
  • Architecture clarification
  • Scaffolding
  • Other

Checklist

  • The change is focused and scoped.
  • Related documentation is updated.
  • New structure or direction is explained clearly.
  • I avoided unnecessary detail or premature abstraction.

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 updates the API auth/user model to match the latest DB schema by moving to username + full_name, switches auth flows to HttpOnly cookie-delivered tokens with refresh rotation (family-based revocation), and seeds a default admin user from environment-provided credentials during bootstrap.

Changes:

  • Replace email-based identity with username (and name → full_name) across domain, persistence, handlers, docs, and tests.
  • Implement cookie-based login/refresh/logout, including refresh-token rotation with family revocation and a Redis-backed refresh store.
  • Add startup admin seeding plus new config/env wiring (ADMIN_USERNAME, ADMIN_PASSWORD, COOKIE_SECURE) and deployment examples.

Reviewed changes

Copilot reviewed 32 out of 32 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
services/api/test/integration/user_test.go Updates integration tests to use username/full_name and new auth handler signature/cookie config.
services/api/test/integration/auth_test.go Updates integration auth tests/fakes for username auth + cookie token delivery + refresh store.
services/api/migrations/000001_init.sql Aligns initial schema with username/full_name and username index.
services/api/internal/transport/http/presenter/response.go Updates conflict mapping to ErrUsernameTaken.
services/api/internal/transport/http/middleware/authn.go Adds cookie-based access token support with Authorization header fallback.
services/api/internal/transport/http/handler/user_handler_test.go Updates user handler unit tests for new fields/errors.
services/api/internal/transport/http/handler/user_handler.go Uses Username/FullName in create/update paths.
services/api/internal/transport/http/handler/auth_handler_test.go Updates auth handler unit tests for cookie-based flows and refresh token cookie usage.
services/api/internal/transport/http/handler/auth_handler.go Implements cookie-based login/refresh/logout and cookie helpers/config.
services/api/internal/transport/http/dto/user_dto.go Renames DTO fields to username/full_name and response mapping.
services/api/internal/transport/http/dto/auth_dto.go Switches login to username and removes token responses; retains empty RefreshRequest type.
services/api/internal/service/user/user_service_test.go Updates service tests to username/full_name and ErrUsernameTaken.
services/api/internal/service/user/user_service.go Enforces username uniqueness and stores FullName.
services/api/internal/service/auth/auth_service_test.go Updates auth service tests for family-based rotation/revocation behavior.
services/api/internal/service/auth/auth_service.go Implements refresh rotation with family revocation + grace-period reuse handling.
services/api/internal/repository/redis/refresh_token_store.go Adds Redis refresh-token first-use tracking and family revocation flags.
services/api/internal/repository/postgres/user_repository.go Renames persisted fields to username/full_name and updates lookup method.
services/api/internal/platform/token/jwt_manager_test.go Updates token tests for Username + FamilyID claims.
services/api/internal/platform/token/jwt_manager.go Adds FamilyID to JWT claims and updates issue methods’ signatures.
services/api/internal/domain/user/service.go Updates Create/Update inputs to Username/FullName.
services/api/internal/domain/user/repository.go Repository now looks up by username.
services/api/internal/domain/user/errors.go Replaces ErrEmailTaken with ErrUsernameTaken.
services/api/internal/domain/user/entity.go Replaces Email/Name with Username/FullName.
services/api/internal/domain/auth/service.go Refresh now returns rotated TokenPair; logout revokes by familyID.
services/api/internal/domain/auth/claims.go Replaces Email with Username and introduces FamilyID claim.
services/api/internal/config/load.go Loads admin creds and cookie secure flag from env.
services/api/internal/config/config.go Adds Admin config and CookieSecure server config.
services/api/internal/bootstrap/app.go Wires refresh store, cookie config, and seeds default admin account at startup.
docs/api/http-design.md Updates HTTP design docs to match cookie auth and username/full_name model.
deploy/docker-compose.prod.yml Adds COOKIE_SECURE + admin env vars.
deploy/docker-compose.dev.yml Adds JWT TTLs, COOKIE_SECURE, and admin env vars for dev.
deploy/.env.production.example Documents new cookie/admin environment variables.

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

Comment thread services/api/internal/config/load.go Resolved

Copilot AI commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

@pikann I've opened a new pull request, #45, 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, #46, to work on those changes. Once the pull request is ready, I'll request review from you.

@pikann
pikann merged commit f76f1ef into 31-epic-authentication-authorization Mar 25, 2026
4 checks passed
@pikann
pikann deleted the feature/implement-auth-apis branch March 25, 2026 05:05
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.

3 participants