diff --git a/.env.example b/.env.example index 1e28dab..33b653e 100644 --- a/.env.example +++ b/.env.example @@ -70,7 +70,8 @@ SMS_PROVIDER = SMS_API_KEY = AUTH_SMS_TEMPLATE = EXP_OTP_TIME = -FAKE_OTP = +# Development-only fixed OTP. Production rejects true at startup. +FAKE_OTP = false # --------------------------------------------- # 🌐 Proxy Configuration (Local Development Only) diff --git a/src/core/config/config.schema.ts b/src/core/config/config.schema.ts index e899863..dd8df37 100644 --- a/src/core/config/config.schema.ts +++ b/src/core/config/config.schema.ts @@ -25,6 +25,10 @@ export class EnvironmentVariables { }) NODE_ENV: Environment; + @IsOptional() + @IsBooleanString({ message: "FAKE_OTP must be boolean" }) + FAKE_OTP?: string; + // --------------------------------------------------------- // @IsNumber( diff --git a/src/core/config/config.validation.ts b/src/core/config/config.validation.ts index c2fce79..8215c90 100644 --- a/src/core/config/config.validation.ts +++ b/src/core/config/config.validation.ts @@ -14,6 +14,15 @@ export function validate(config: Record) { throw new Error("AI_DAMAGE_URL is required when AI_DAMAGE_ENABLED=true"); } + if ( + validatedConfig.NODE_ENV === "production" && + String(validatedConfig.FAKE_OTP ?? "").toLowerCase() === "true" + ) { + throw new Error( + "FAKE_OTP must be disabled in production so login codes are delivered by the configured SMS provider", + ); + } + const errors = validateSync(validatedConfig, { skipMissingProperties: false, }); diff --git a/src/price-estimation/price-estimation.spec.ts b/src/price-estimation/price-estimation.spec.ts index 46b533d..1a29852 100644 --- a/src/price-estimation/price-estimation.spec.ts +++ b/src/price-estimation/price-estimation.spec.ts @@ -885,5 +885,11 @@ describe("Swagger and local validation", () => { expect(() => validate({ ...base, OPENAI_PRICE_ESTIMATION_TIMEOUT_MS: 600001 }), ).toThrow(); + expect(() => + validate({ ...base, NODE_ENV: "production", FAKE_OTP: "true" }), + ).toThrow("FAKE_OTP must be disabled in production"); + expect(() => + validate({ ...base, NODE_ENV: "production", FAKE_OTP: "false" }), + ).not.toThrow(); }); });