Fix TypeScript type inference loss when dynamically constructing Zod object schemas. Use when: (1) `z.infer<typeof schema>` produces `Record<string, unknown>` instead of typed fields, (2) Building a schema factory that constructs `z.object()` from dynamic field maps, (3) Component props typed from Zod schema show 'unknown' for all fields, (4) Type error "'data.fieldName' is of type 'unknown'" after refactoring schemas to use a factory pattern. Covers Zod 3 and Zod 4.
Access the Home Assistant REST API using environment variables HA_URL and HA_TOKEN exported in ~/.zshrc. Use when: (1) need to query Home Assistant entity states, (2) need to call HA services programmatically, (3) need to debug or inspect HA integration state, (4) user asks to interact with their Home Assistant instance. Covers authentication, common endpoints, and usage patterns.
Fix Better Auth performance anti-pattern: manual db.$setAuth() vs. reusing cached client. Use when: (1) Server actions or components create new auth contexts with db.$setAuth(), (2) Functions accept User parameter just to create auth context, (3) Dashboard or data-heavy pages are slow (>500ms), (4) Multiple sequential auth operations in same request. Applies to Better Auth v1.4.10+ with JWE cookie cache and ZenStack ORM.
Fix for "An error occurred in the Server Components render" in Next.js production builds when using ZenStack ORM with Better Auth. Use when: (1) Generic Server Components error in production with no stack trace, (2) Works in dev but fails in production, (3) Using manual db.$setAuth() instead of authenticated client from auth()/requireRole(). Symptoms include Sentry errors with digest but no details, or blank error pages. Solution: Always use the pre-configured db client from auth() or requireRole() result instead of manually creating auth context with db.$setAuth({ id, role }).
Fix timezone drift when using JavaScript Date methods with UTC-stored times. Use when: (1) Times shift by user's timezone offset (e.g., 09:00 UTC becomes 10:00 in BST browsers), (2) Database stores times in UTC but display shows wrong hours, (3) Inconsistent time behavior across users in different timezones, (4) Using getHours/getMinutes/setHours with Date objects that should stay in UTC. Replace local time getters/setters with UTC variants to prevent automatic timezone conversion.
Refactor Next.js + Better Auth authentication to minimal API with discriminated unions. Use when: (1) Too many auth helper functions causing maintenance burden, (2) Want perfect type safety without optional chaining, (3) Need to optimize auth performance with aggressive cookie caching, (4) Using Better Auth v1.4+ with Next.js 16 App Router and ZenStack ORM. Covers progressive refactoring from backward-compatible to breaking changes, discriminated union type patterns, and systematic multi-file migration.
Fix TypeScript errors when integrating react-big-calendar drag-and-drop addon in Next.js/React projects. Use when: (1) Getting "Module has no exported member 'EventInteractionArgs'" error, (2) EventWrapperProps type missing 'children' property causing type errors, (3) stringOrDate type mismatches in onEventDrop/onEventResize handlers. Covers proper type imports and generic type parameters for withDragAndDrop HOC.
Integrate react-big-calendar with Next.js 16 App Router and shadcn/ui. Use when: (1) Need to add a visual calendar to Next.js app, (2) Want calendar that works with server/client component split, (3) Need to integrate with shadcn/ui theming, (4) Building scheduling or availability features. Covers component structure, CSS imports in client components, date-fns localizer setup, and event styling with shadcn variables.