Kế hoạch triển khai: Authentication Feature
Status: Production — tài liệu này phục vụ onboarding + cải tiến
1. Hiện trạng
Triển khai hiện có
AuthControllercung cấp 4 endpoints:generate-code,sign-in,logout,check-email.LoginHandlerFactory+ Strategy pattern:Web3AuthLoginHandler,ImmutableLoginHandler.- JWT stateless với
JwtTokenFilterkiểm tra mọi request. - Session management: Redis-based single-device per site.
- Wallet auto-creation và async initialization.
Vấn đề đã biết
| # | Vấn đề | Mức độ |
|---|---|---|
| 1 | Rate limit generate-code bị comment out |
High |
| 2 | validateCode() trong signIn() bị comment out |
Medium |
| 3 | create-account-fake endpoint không có guard |
Medium |
| 4 | Async secondary wallet không có retry/monitoring | Low |
2. Kế hoạch cải tiến
Phase 1: Security hardening (ưu tiên cao)
- Task 1-1: Re-enable rate limit cho
generate-code - Task 1-2: Review + re-enable
validateCode()trongsignIn() - Task 1-3: Guard
create-account-fakebằng internal IP check hoặc xóa
Phase 2: Observability
- Task 2-1: Thêm audit log cho auth events (login success/fail/banned/logout)
- Task 2-2: Metrics: login rate per provider, failed logins, session invalidations
Phase 3: Resilience
- Task 3-1: Retry + alert cho async secondary wallet creation failures
- Task 3-2: Monitor session repository Redis health
Phase 4: Testing
- Task 4-1: Integration test cho toàn bộ auth flows (new user / existing user / banned)
- Task 4-2: Concurrent login test (lock mechanism)
- Task 4-3: Edge cases: expired code, invalid provider token, missing wallet
3. Quan hệ phụ thuộc
graph TD
T1_1[Task 1-1: Rate limit] --> T4_1
T1_2[Task 1-2: validateCode] --> T4_1
T1_3[Task 1-3: fake account guard] --> T4_1
T2_1[Task 2-1: Audit log] --> T4_2
T2_2[Task 2-2: Metrics] --> T4_2
T3_1[Task 3-1: Wallet retry] --> T4_3
T3_2[Task 3-2: Redis health] --> T4_3
T4_1[Task 4-1: Integration test]
T4_2[Task 4-2: Concurrent login test]
T4_3[Task 4-3: Edge cases]
4. Timeline (Gantt)
gantt
title Authentication Feature - Improvement Plan
dateFormat YYYY-MM-DD
section Phase 1 Security
Task 1-1 Rate limit :crit, t1_1, 2025-01-01, 1d
Task 1-2 validateCode :crit, t1_2, after t1_1, 2d
Task 1-3 fake account :t1_3, after t1_1, 1d
section Phase 2 Observability
Task 2-1 Audit log :t2_1, after t1_2, 2d
Task 2-2 Metrics :t2_2, after t2_1, 2d
section Phase 3 Resilience
Task 3-1 Wallet retry :t3_1, after t1_2, 3d
Task 3-2 Redis health :t3_2, after t3_1, 1d
section Phase 4 Testing
Task 4-1 Integration test :t4_1, after t1_3, 3d
Task 4-2 Concurrent test :t4_2, after t4_1, 2d
Task 4-3 Edge cases :t4_3, after t4_2, 2d
Ngày trong chart là tương đối để thể hiện thứ tự phụ thuộc.
5. Thứ tự triển khai đề xuất
- Đầu tiên: Task 1-1, 1-3 (không phụ thuộc, fix security ngay)
- Tiếp theo: Task 1-2 (cần test kỹ trước khi enable)
- Sau đó: Task 2-1, 2-2, 3-1, 3-2 (song song)
- Cuối: Phase 4 Testing sau khi hoàn tất tất cả
6. Rủi ro
| Rủi ro | Ảnh hưởng | Biện pháp |
|---|---|---|
Re-enable validateCode làm vỡ existing flow |
Login fail hàng loạt | Test kỹ trên staging, rollout theo feature flag |
| Rate limit quá chặt | User bị chặn legitimate login | Tune threshold theo traffic thực tế |
| Redis session expire quá sớm | User bị logout bất ngờ | Calibrate TTL theo session analytics |
| Async wallet failure không alert | User thiếu wallet | Add dead letter queue + alert |