fix(admin-ui): не резолвить «anonymous» через /admin/users/{sub}/display

Backend currentUserId() возвращает литерал "anonymous" когда JWT отсутствует
(ORDINIS_AUTH_REQUIRED=false fallback). Audit / draft entries сохраняют
этот sub в БД. Frontend UserCell дёргал /admin/users/anonymous/display
→ 404 → catch → display "—". Логически ок, но в консоли DevTools мусорный
404 на каждом рендере таблицы.

Skip endpoint когда uuid === "anonymous":
- useResolveUserDisplay: enabled = uuid && uuid !== 'anonymous'
- useUserDisplay: short-circuit ветка возвращает display: 'anonymous'

UX без изменений (раньше показывал «—» с full UUID в tooltip; теперь
показывает «anonymous» без 404 в консоли).
This commit is contained in:
Zimin A.N.
2026-05-25 18:34:20 +03:00
parent 936231c8e3
commit 8c0b74cbf8
+11 -1
View File
@@ -24,7 +24,11 @@ type UserDisplayInfo = {
const useResolveUserDisplay = (uuid: string | null | undefined) => const useResolveUserDisplay = (uuid: string | null | undefined) =>
useQuery({ useQuery({
queryKey: ['user-display', uuid] as const, queryKey: ['user-display', uuid] as const,
enabled: Boolean(uuid), // Не дёргаем endpoint для литерала "anonymous" — это не UUID, а маркер
// отсутствия JWT subject (см. backend currentUserId fallback когда
// ORDINIS_AUTH_REQUIRED=false). Резолв даёт 404, в консоли мусор.
// Вместо запроса фронт сам подменит на «anonymous» в useUserDisplay ниже.
enabled: Boolean(uuid) && uuid !== 'anonymous',
staleTime: 5 * 60 * 1000, staleTime: 5 * 60 * 1000,
retry: false, retry: false,
queryFn: async (): Promise<UserDisplayInfo | null> => { queryFn: async (): Promise<UserDisplayInfo | null> => {
@@ -86,6 +90,12 @@ export function useUserDisplay(uuid: string | null | undefined): {
if (!fullId) { if (!fullId) {
return { display: 'anonymous', isMe: false, fullId: '' } return { display: 'anonymous', isMe: false, fullId: '' }
} }
// "anonymous" — литерал из backend currentUserId() когда нет JWT
// (ORDINIS_AUTH_REQUIRED=false и токен не дошёл). Не UUID, не резолвим
// через /admin/users/{sub}/display — там будет 404, шум в консоли.
if (fullId === 'anonymous') {
return { display: 'anonymous', isMe: false, fullId }
}
const currentSub = auth.user?.profile?.sub const currentSub = auth.user?.profile?.sub
const isMe = Boolean(currentSub) && currentSub === fullId const isMe = Boolean(currentSub) && currentSub === fullId
if (isMe) { if (isMe) {