Files
edr-platform/apps/edr-freight-api/src/common/resolve-auth-user-id.ts
2026-06-04 15:16:27 +03:00

13 lines
403 B
TypeScript

import { UnauthorizedException } from '@nestjs/common';
export type AuthUserPayload = { id?: string; sub?: string } | null | undefined;
/** Resolve IAM user id from JWT payload attached by JwtGuard. */
export function resolveAuthUserId(user: AuthUserPayload): string {
const id = user?.id ?? user?.sub;
if (!id) {
throw new UnauthorizedException('Authentication required');
}
return id;
}