import { useMatrixClient } from './useMatrixClient'; // Returns the current user's MXID in any subtree that mounts only after // authentication has resolved (`` and everything inside it). // Throws if the SDK has no user ID — that's an invariant violation, not a // soft-failure path: by the time post-login components render, the SDK // already has a session. Prefer this over `mx.getUserId() ?? ''` so a // broken invariant surfaces loudly instead of silently defaulting to '' and // writing empty-string user IDs into account-data / storage keys. // // For utility functions that aren't React hooks, call `mx.getSafeUserId()` // directly — it's the same contract. export function useAuthedUserId(): string { const mx = useMatrixClient(); return mx.getSafeUserId(); }