認證 API
使用者認證端點 — 登入、登出、Token 管理、密碼重設。
POST /auth/signup
建立新使用者帳號。
Request Body
| 參數 | 類型 | 必填 | 說明 |
|---|---|---|---|
| `email` | string | ✅ | 使用者 email |
| `password` | string | ✅ | 密碼(最少 6 字元) |
| `username` | string | ❌ | 使用者名稱 |
Response (201)
{"user_id": "abc123", "message": "User created successfully"}
POST /auth/token/refresh
重新整理使用者的 access token。
Headers
- `Authorization`: `Bearer <current_token>`
Response (200)
{"access_token": "new_jwt_token", "token_type": "Bearer", "expires_at": 1712000000}
GET /auth/me
取得目前已認證使用者的資訊。
Headers
- `Authorization`: `Bearer <token>`
Response (200)
{"user_id": "abc123", "email": "user@example.com", "roles": ["athlete"], "is_verified": true, "is_active": true}
POST /auth/logout
登出目前使用者。Client 端應丟棄 token。
Response (200)
{"message": "Successfully logged out"}
POST /auth/verify-email
驗證使用者 email。
Request Body
| 參數 | 類型 | 必填 | 說明 |
|---|---|---|---|
| `code` | string | ✅ | 驗證碼 |
POST /auth/change-password
變更密碼。
Request Body
| 參數 | 類型 | 必填 | 說明 |
|---|---|---|---|
| `current_password` | string | ✅ | 目前密碼 |
| `new_password` | string | ✅ | 新密碼 |
POST /auth/password-reset
發送密碼重設 email。
Request Body
| 參數 | 類型 | 必填 | 說明 |
|---|---|---|---|
| `email` | string | ✅ | 使用者 email |
POST /auth/password-reset/confirm
使用重設碼完成密碼重設。
Request Body
| 參數 | 類型 | 必填 | 說明 |
|---|---|---|---|
| `code` | string | ✅ | 重設碼 |
| `new_password` | string | ✅ | 新密碼 |
POST /auth/complete-signup
完成註冊流程(設定 profile)。
Request Body
| 參數 | 類型 | 必填 | 說明 |
|---|---|---|---|
| `username` | string | ✅ | 使用者名稱 |
| `display_name` | string | ❌ | 顯示名稱 |
POST /auth/token-exchange
用 Firebase ID Token 換取 NexRex JWT。
Request Body
| 參數 | 類型 | 必填 | 說明 |
|---|---|---|---|
| `firebase_token` | string | ✅ | Firebase ID Token |
Response (200)
{"access_token": "nexrex_jwt", "token_type": "Bearer", "expires_at": 1712000000, "user_id": "abc123"}
POST /auth/impersonate
以其他使用者身分操作(僅限管理員/教練)。
Request Body
| 參數 | 類型 | 必填 | 說明 |
|---|---|---|---|
| `target_user_id` | string | ✅ | 目標使用者 ID |
POST /auth/exit-impersonation
退出代理操作,恢復原始身分。