import { useRouteContext } from "@tanstack/react-router";
import { canWriteAsViewer } from "~/lib/email-verification";
export function useViewer() {
return useRouteContext({ from: "__root__", select: (context) => context.viewer ?? null });
}
/** On Pro or with a card on file: shows the Pro badge and never sees the upgrade nudge. */
export function useSupporter() {
return useRouteContext({ from: "__root__", select: (context) => context.supporter });
}
export function useUnreadNotifications() {
return useRouteContext({ from: "__root__", select: (context) => context.unreadNotifications });
}
/** A signed-in viewer who may not write or pay until they verify their email (AUTH-B1). */
export function useEmailUnverified() {
return useRouteContext({
from: "__root__",
select: (context) => Boolean(context.viewer) && !canWriteAsViewer(context.viewer ?? null),
});
}