refactor(auth): address server review feedback
- Extract auth DTOs, cookie/JWT helpers and the generic duration parser. - Configure the session cookie and map domain auth failures to HTTP responses. - Add typed Swagger responses and focused regression coverage.
This commit is contained in:
1 parent
72e127888c
commit
1830feb71b
18 files changed
+399
-208
No files matched your search
@@ -12,16 +12,7 @@ import {
|
||||
|
||||
import { appPackage } from "../common/app-package";
|
||||
|
||||
export function authDurationSeconds(value: string): number | null {
|
||||
const match = /^(\d+)(s|m|h|d)$/.exec(value);
|
||||
if (!match) return null;
|
||||
const amount = Number(match[1]);
|
||||
const multiplier = { s: 1, m: 60, h: 3600, d: 86400 }[
|
||||
match[2] as "s" | "m" | "h" | "d"
|
||||
];
|
||||
const seconds = amount * multiplier;
|
||||
return Number.isSafeInteger(seconds) && seconds > 0 ? seconds : null;
|
||||
}
|
||||
import { durationSeconds } from "../common/interval";
|
||||
|
||||
export enum TraceMode {
|
||||
On = "on",
|
||||
@@ -96,6 +87,10 @@ export class AppConfig {
|
||||
@IsString()
|
||||
AUTH_JWT_SECRET: string = "";
|
||||
|
||||
/** Cookie name used for browser sessions. */
|
||||
@IsString()
|
||||
AUTH_COOKIE_NAME: string = "liqa_auth";
|
||||
|
||||
@IsString()
|
||||
AUTH_JWT_EXPIRES_IN: string = "24h";
|
||||
|
||||
@@ -130,7 +125,7 @@ export function validateAppConfig(config: Record<string, unknown>): AppConfig {
|
||||
}
|
||||
if (
|
||||
validated.AUTH_ENABLED &&
|
||||
authDurationSeconds(validated.AUTH_JWT_EXPIRES_IN) === null
|
||||
durationSeconds(validated.AUTH_JWT_EXPIRES_IN) === null
|
||||
) {
|
||||
throw new Error(
|
||||
"AUTH_JWT_EXPIRES_IN must be a positive duration such as 30m, 1h, or 24h.",
|
||||
|
||||
Reference in new issue
Block a user