Deriv bot control plane

Dashboard trading bot với session lưu DB và Deriv token luôn ở server.

App này được scaffold theo hướng production: `Next.js App Router`, `NextAuth v5`, `Drizzle + Turso`, admin approval flow, API tạo OTP WebSocket URL và dashboard để start/stop bot, xem lịch sử trade.

Database session

Cookie chỉ chứa session token. Khi nối Turso, server có thể revoke user ngay khi admin đổi trạng thái.

Encrypted Deriv token

Deriv access token được AES-256-GCM encrypt trước khi lưu. Client chỉ nhận OTP URL ngắn hạn.

Approval gate

User mới vào trạng thái pending. Middleware và server guard chặn dashboard cho đến khi admin approve.

Flow bảo mật

`Google Login` → server tạo hoặc cập nhật user → session lưu ở database.

`/api/deriv/connect` mã hóa token trước khi ghi DB, không trả token về browser.

`/api/bot/start` giải mã token ở server, gọi Deriv để lấy OTP WebSocket URL rồi mới trả dữ liệu tối thiểu cho client.

Mode demo trong repo này

Nếu chưa cấu hình Google hoặc Turso, app vẫn render được bằng demo data để bạn kiểm tra luồng UI. Khi thêm biến môi trường, app tự chuyển sang Google OAuth và database session.