feat: ownerOf(event) helper and ownerId in task DTO

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-06-11 08:26:23 +00:00
parent 42abf35bff
commit 0e16738624
2 changed files with 12 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ export interface TaskDto {
description: string | null; description: string | null;
source: string; source: string;
consumed: boolean; consumed: boolean;
ownerId: string | null;
createdAt: string; createdAt: string;
} }
@@ -18,6 +19,7 @@ export function toTaskDto(row: TaskRow): TaskDto {
description: row.description, description: row.description,
source: row.source, source: row.source,
consumed: row.consumed, consumed: row.consumed,
ownerId: row.owner_id,
createdAt: new Date(row.created_at).toISOString(), createdAt: new Date(row.created_at).toISOString(),
}; };
} }

10
server/utils/session.ts Normal file
View File

@@ -0,0 +1,10 @@
import { createError, type H3Event } from "h3";
/** The authenticated caller's Zitadel sub — the ownership key for all row scoping. */
export function ownerOf(event: H3Event): string {
const sub = (event.context.user as { sub?: unknown } | undefined)?.sub;
if (typeof sub !== "string" || !sub) {
throw createError({ statusCode: 401, statusMessage: "Unauthorized" });
}
return sub;
}