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;
}
