Skip to content

refactor: Consolidate JWT module configuration into a shared module #205

@Xhristin3

Description

@Xhristin3

Problem Statement

JwtModule is registered independently in two modules with different fallback secrets:

  • api/src/auth/auth.module.ts:12secret: process.env.JWT_SECRET ?? "dev-secret-change-me"
  • api/src/gateways/gateways.module.ts:15secret: secret ?? "dev-insecure-secret-change-me"

Two different secrets, two JwtModule instances, two signOption configs. The GatewaysModule uses registerAsync while AuthModule uses register.

Evidence

// AuthModule: 15min expiry
JwtModule.register({ secret: process.env.JWT_SECRET ?? "dev-secret-change-me", signOptions: { expiresIn: "15m" } })

// GatewaysModule: 1h expiry, async registration
JwtModule.registerAsync({ useFactory: () => { ... return { secret: secret ?? "dev-insecure-secret-change-me", signOptions: { expiresIn: "1h" } } } })

Impact

Maintenance burden, inconsistent expiry times (auth tokens 15min vs gateway verification expecting 1h), and two fallback secrets. If either module's config is updated independently, JWTs may be rejected by one but accepted by the other.

Proposed Solution

  1. Create api/src/config/jwt.config.ts with a shared JwtModule.registerAsync factory
  2. Import this shared config in both AuthModule and GatewaysModule
  3. Use consistent expiry (15min for access tokens)
  4. Single source of truth for JWT secret

Acceptance Criteria

  • Single JWT configuration factory used by both modules
  • Consistent token expiry across all JWT consumers
  • No duplicate fallback secrets
  • All existing auth and WebSocket tests pass

File Map

  • api/src/config/jwt.config.ts — new shared config
  • api/src/auth/auth.module.ts — use shared config
  • api/src/gateways/gateways.module.ts — use shared config

Labels: refactoring
Priority: Medium | Difficulty: Intermediate | Estimated Effort: 1d


Labels: refactoring
Priority: Medium | Difficulty: Intermediate | Estimated Effort: 1d
Backlog ID: REPO-022

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions