Skip to content

feat: add user authentication and React frontend - #24

Merged
l3yx merged 5 commits into
oritera:dev-0.3.0from
ZacharyZcR:feat/user-auth-react
Jun 30, 2026
Merged

l3yx merged 5 commits into
oritera:dev-0.3.0from
ZacharyZcR:feat/user-auth-react

Conversation

@ZacharyZcR

Copy link
Copy Markdown
Collaborator

Summary

  • Add user authentication system (JWT + bcrypt) with register/login/me endpoints
  • Initialize React frontend (Vite + TypeScript + Ant Design) as a separate web/ project
  • Add CORS middleware for frontend-backend separation
  • Database migration compatible with existing SQLite databases

Backend changes

  • cairn/server/auth.py — JWT token management, password hashing, get_current_user dependency
  • cairn/server/routers/auth.py — POST /auth/register, POST /auth/login, GET /auth/me
  • cairn/server/db.py — users and kv tables with migration for existing databases
  • cairn/server/app.py — CORS middleware + auth router registration
  • New dependencies: pyjwt, bcrypt

Frontend (web/)

  • Vite + React + TypeScript project
  • Ant Design UI components
  • Pages: Login, Register (with password confirmation), Dashboard (project list)
  • AuthGuard route protection
  • API client with auto JWT attachment and 401 redirect
  • Vite proxy config for development

Architecture note

Existing internal APIs (/projects, /intents, etc.) remain unauthenticated — the Dispatcher communicates via these endpoints within the Docker network. Full API authentication is deferred to the v1.0 gRPC rewrite.

Test plan

  • Backend: 61 existing tests pass, zero regression
  • Frontend: TypeScript zero errors, Vite build succeeds
  • Manual: register a user, login, verify dashboard loads project list
  • Manual: verify unauthenticated access redirects to login page

Backend:
- Add users table and kv table to SQLite schema with migration
- Implement JWT auth (bcrypt password hashing, token issue/verify)
- Add /auth/register, /auth/login, /auth/me API endpoints
- Add CORS middleware for frontend separation
- Add pyjwt and bcrypt dependencies

Frontend (web/):
- Initialize Vite + React + TypeScript project
- Add Ant Design UI and React Router
- Implement Login, Register pages with form validation
- Implement Dashboard page with project list table
- Add AuthGuard route protection component
- Add API client with auto JWT attachment and 401 redirect
- Configure Vite proxy for development API forwarding
- Add require_auth dependency to all routers (projects, intents, hints, export, settings)
- Support dual auth: JWT (frontend users) and API Key (dispatcher)
- Add server_token field to DispatchConfig for dispatcher authentication
- CairnClient sends X-API-Key header when server_token is configured
- Update dispatch.example.yaml with server_token field
- Update docker-compose.yaml with CAIRN_API_KEYS environment variable
- Fix healthcheck endpoint to use /openapi.json (auth-free)
- Update tests to use API Key authentication
21 tests covering:
- Registration: success, duplicate username, validation errors
- Login: valid credentials, wrong password, nonexistent user
- JWT: /auth/me with valid/invalid/missing token
- API Key: correct key grants access, wrong key rejected
- Protected routes: 401 without auth on projects/settings/hints
- JWT on protected routes: projects and settings accessible
- Auth-free endpoints: register, login, openapi.json
- Full flow: register -> login -> me -> create project -> export
…eact

# Conflicts:
#	cairn/src/cairn/server/routers/export.py
#	cairn/uv.lock
@l3yx
l3yx merged commit add535a into oritera:dev-0.3.0 Jun 30, 2026
1 check passed
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.

2 participants