Summary
OTP_SECRET is configured and validated in env.validation.ts but no 2FA system exists. The configuration is in place but unused.
Why This Matters
For a financial platform, 2FA is a standard security requirement — especially for admin users and large transaction approvals.
What Needs to Be Done
- Build
POST /auth/2fa/enable: generate TOTP secret, return QR code URI
- Build
POST /auth/2fa/verify: validate OTP and activate 2FA
- Build
POST /auth/2fa/disable: require current OTP to disable
- Generate 10 single-use backup codes stored hashed
- Build recovery flow for users who lose their authenticator app
- Enforce 2FA on login — users with 2FA enabled must provide OTP
- Write comprehensive E2E tests
Key Files
src/modules/auth/services/totp.service.ts — TOTP secret generation, QR URI, verification
src/modules/auth/auth.controller.ts — add 2fa endpoints
src/modules/users/entities/user.entity.ts — add twoFactorSecret, twoFactorEnabled, backupCodes fields
src/database/migrations/xxxx-add-2fa-fields.ts — migration
src/modules/auth/auth.service.ts — enforce 2FA check in login flow
test/two-factor-auth.e2e-spec.ts — E2E tests
Acceptance Criteria
Constraints
- TOTP secrets must be encrypted at rest
- Backup codes must be hashed and single-use
- QR code URI must be compatible with standard TOTP apps (Google Authenticator, Authy)
- Complexity: High — 200 points
Summary
OTP_SECRETis configured and validated inenv.validation.tsbut no 2FA system exists. The configuration is in place but unused.Why This Matters
For a financial platform, 2FA is a standard security requirement — especially for admin users and large transaction approvals.
What Needs to Be Done
POST /auth/2fa/enable: generate TOTP secret, return QR code URIPOST /auth/2fa/verify: validate OTP and activate 2FAPOST /auth/2fa/disable: require current OTP to disableKey Files
src/modules/auth/services/totp.service.ts— TOTP secret generation, QR URI, verificationsrc/modules/auth/auth.controller.ts— add 2fa endpointssrc/modules/users/entities/user.entity.ts— add twoFactorSecret, twoFactorEnabled, backupCodes fieldssrc/database/migrations/xxxx-add-2fa-fields.ts— migrationsrc/modules/auth/auth.service.ts— enforce 2FA check in login flowtest/two-factor-auth.e2e-spec.ts— E2E testsAcceptance Criteria
POST /auth/2fa/enablereturns TOTP secret and QR code URIPOST /auth/2fa/backupgenerates 10 single-use backup codes stored hashedPOST /auth/2fa/disablerequires valid OTPConstraints