Skip to content

Refactor Phase 3: Auth Session - #53

Merged
1mimhe merged 5 commits into
masterfrom
refactor/auth-session
Sep 3, 2026
Merged

1mimhe merged 5 commits into
masterfrom
refactor/auth-session

Conversation

@1mimhe

@1mimhe 1mimhe commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

No description provided.

- Add common/utils/codes.ts: generateSecureOtp (6-digit zero-padded crypto-random),
  generateUniqueCode, generateTripCode and generateTrackingCode (base32)
- Keep legacy generateCode as a deprecated export (trip delivery code migrates in Phase 4)
- utilities.ts re-exports all generators for backward compatibility
- Make generateAccessToken/generateTempToken/generateProgressToken public with
  dedicated payload types (token.types.ts); keep verifyToken unchanged
- Read JWT_*_EXPIRES_IN via ConfigService with defaults 20d/20m/1d (fixes C-2:
  no hardcoded expiries); register optional keys in config-names + env validation
- Regroup private helpers at the end of the class
- Define S3StoragePort (interim port, full StoragePort lands in Phase 5) and
  inject it via the S3_STORAGE_PORT symbol
- Bind the port to S3Service with useExisting in user.module.ts
- Keep presigned-URL building behavior identical
- Extract OtpService (domain): owns send/verify, attempt tracking, blocking and
  the send window. Reads limits through an injected OTP_CONFIG value object so
  only the canonical MAX_SEND_ATTEMPTS key is used (fixes C-1), and accesses the
  OTP cache through the named OTP_CACHE provider (fixes C-3)
- Extract AuthStateMachine (domain): pure transporter auth-state computation
- Extract TransporterSignupService (application): sender + transporter stage-1
  signup orchestration
- Extract session-utils: setUserState/setSessionAuth/clearAuthData session helpers
- Includes unit specs for each extracted unit (fake timers for OTP, mocked cache)
…cted services

- Slim AuthService to a thin facade delegating to OtpService, AuthStateMachine
  and TransporterSignupService; inject the state machine and signup service in
  AuthModule with OtpService (OTP_CACHE, OTP_CONFIG factory providers)
- Switch the OTP contract from a 5-digit number to a zero-padded 6-digit string:
  CheckOtpDto validates a 6-char numeric string, SmsService.sendOtp takes a
  string, OtpData.code becomes string
- Move cookie/session wiring to the controller and set state via session-utils;
  remove dead code (unused maxAge/config reads)
- Rewrite controller/service specs against the new collaborators with all
  guards mocked via overrideGuard
@1mimhe
1mimhe merged commit ea84577 into master Sep 3, 2026
1 check passed
@1mimhe
1mimhe deleted the refactor/auth-session branch September 3, 2026 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant