batch3 T3 review fix: swap req.user! for requireUser; document ws/user guard

Replaces six non-null assertions on req.user with the requireUser helper
from auth.ts, which throws a descriptive error if the auth hook didn't
populate req.user. Adds an inline comment in /api/ws/user explaining the
manual auth check is defensive (the global hook already enforces auth).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-15 15:10:20 +00:00
parent 8fc525eab9
commit 124beae2bc
4 changed files with 11 additions and 6 deletions

View File

@@ -2,6 +2,7 @@ import type { FastifyInstance } from 'fastify';
import { z } from 'zod';
import type { Sql } from '../db.js';
import type { Message, Session } from '../types/api.js';
import { requireUser } from '../auth.js';
const SendBody = z.object({
content: z.string().min(1).max(64_000),
@@ -76,7 +77,7 @@ export function registerMessageRoutes(
result.user_message_id,
parsed.data.content
);
handlers.enqueueInference(req.params.id, result.assistant_message_id, req.user!);
handlers.enqueueInference(req.params.id, result.assistant_message_id, requireUser(req));
reply.code(202);
return result;
@@ -132,7 +133,7 @@ export function registerMessageRoutes(
});
handlers.publishMessagesDeleted(sessionId, deletedIds);
handlers.enqueueInference(sessionId, newAssistantId, req.user!);
handlers.enqueueInference(sessionId, newAssistantId, requireUser(req));
reply.code(202);
return { assistant_message_id: newAssistantId };