feat: implement user authentication module
- Backend (FastAPI): - External API authentication (pj-auth-api.vercel.app) - JWT token validation with Redis session storage - RBAC with department isolation - User, Role, Department models with pjctrl_ prefix - Alembic migrations with project-specific version table - Complete test coverage (13 tests) - Frontend (React + Vite): - AuthContext for state management - Login page with error handling - Protected route component - Dashboard with user info display - OpenSpec: - 7 capability specs defined - add-user-auth change archived 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
# Change: Add User Authentication & Authorization
|
||||
|
||||
## Why
|
||||
|
||||
系統需要使用者認證與授權機制作為所有功能的基礎。沒有認證系統,無法識別使用者身份、無法實施權限控制、無法追蹤操作記錄。這是整個專案管理系統的第一個必要模組。
|
||||
|
||||
## What Changes
|
||||
|
||||
- **新增** 外部 API 認證整合 (https://pj-auth-api.vercel.app)
|
||||
- **新增** JWT Token 驗證與 Session 管理
|
||||
- **新增** 使用者資料表 (`pjctrl_users`)
|
||||
- **新增** 部門資料表 (`pjctrl_departments`)
|
||||
- **新增** 角色資料表 (`pjctrl_roles`)
|
||||
- **新增** 預設系統管理員帳號 (`ymirliu@panjit.com.tw`)
|
||||
- **新增** RBAC 權限檢查中間件
|
||||
- **新增** 部門級資料隔離機制
|
||||
|
||||
## Impact
|
||||
|
||||
- **Affected specs**: `user-auth` (新增)
|
||||
- **Affected code**:
|
||||
- Backend: `app/api/auth/`, `app/models/user.py`, `app/core/security.py`
|
||||
- Frontend: `src/contexts/AuthContext.tsx`, `src/pages/Login.tsx`
|
||||
- Database: Migration for `pjctrl_users`, `pjctrl_departments`, `pjctrl_roles`
|
||||
|
||||
## Dependencies
|
||||
|
||||
- 外部認證 API: https://pj-auth-api.vercel.app (必須可用)
|
||||
- MySQL 資料庫連線
|
||||
- Redis (用於 Session 儲存)
|
||||
|
||||
## Success Criteria
|
||||
|
||||
1. 使用者可透過外部 API 完成登入
|
||||
2. JWT Token 正確核發與驗證
|
||||
3. 系統管理員帳號可登入並存取所有資源
|
||||
4. 非授權使用者無法存取受保護的 API
|
||||
5. 部門隔離正確運作
|
||||
Reference in New Issue
Block a user