Repository navigation
feat: implement auth apis - #44
Merged
pikann merged 11 commits intoMar 25, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
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(andname→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.
Contributor
Contributor
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
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 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
emailtousername, and fromnametofull_namein both code and documentation. All relevant structs, interfaces, and database interactions now useusernameandfull_namefields, and JWT claims now carryusernameinstead ofemail. [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
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
FamilyIDin 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
Checklist