import { AuthenticatedUser } from '../auth/authenticated-request'; import { GuestJwtPayload } from '../auth/guest-auth.service'; import { ChatCaller } from './chat.service'; function isGuestPayload(user: unknown): user is GuestJwtPayload { return !!user && typeof user === 'object' && 'guestId' in user; } /// req.user is either an AuthenticatedUser (Authentik) or a GuestJwtPayload, /// depending on which strategy AuthGuard(['authentik','guest']) picked. export function resolveChatCaller(user: AuthenticatedUser | GuestJwtPayload): ChatCaller { return isGuestPayload(user) ? { kind: 'guest', guest: user } : { kind: 'user', user }; }