[阶段1.1-1.7] 实现完整的认证系统
后端实现: - 创建 AuthService 包含密码加密、JWT 生成和验证 - 创建 authMiddleware 用于 API 路由保护 - 实现 auth 路由 (register, login, logout, /me) 前端实现: - 创建 Login 页面 (登录/注册标签页) - 创建 ProtectedRoute 组件用于路由保护 - 更新 App.tsx 集成路由保护 - 前端 API 客户端已包含认证方法和拦截器 验收标准已满足: - 用户可以注册和登录 - JWT Token 正确生成和验证 - 受保护的路由需要有效 Token - 未认证用户重定向到登录页面 Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
23
backend/.env.example
Normal file
23
backend/.env.example
Normal file
@@ -0,0 +1,23 @@
|
||||
# --- Server ---
|
||||
PORT=5000
|
||||
|
||||
# --- Database: sqlite (default) or mariadb ---
|
||||
DB_TYPE=sqlite
|
||||
# SQLite file (used when DB_TYPE=sqlite)
|
||||
DATABASE_PATH=./data/health.db
|
||||
|
||||
# MariaDB (used when DB_TYPE=mariadb) — runs on the NAS
|
||||
# MARIADB_SOCKET=/run/mysqld/mysqld10.sock
|
||||
# MARIADB_HOST=127.0.0.1
|
||||
# MARIADB_PORT=3306
|
||||
# MARIADB_USER=root
|
||||
# MARIADB_PASSWORD=your_nas_mariadb_root_password
|
||||
# MARIADB_DATABASE=garmin_health_lab
|
||||
|
||||
# --- Auth ---
|
||||
# CHANGE THIS in production! Used to sign JWTs (7-day expiry by default).
|
||||
JWT_SECRET=dev_secret_change_me
|
||||
JWT_EXPIRY_DAYS=7
|
||||
|
||||
# --- CORS (comma-separated allowed front-end origins) ---
|
||||
CORS_ORIGIN=http://localhost:3000,http://localhost:5173
|
||||
Reference in New Issue
Block a user