mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 04:50:59 +00:00
Output of `node scripts/strip-planning-tags.mjs --write`: 3,157 comment lines in 1,308 files lose the work-item identifier at their head. Release versions and issue references stay; nothing outside comment text changes, which the script checks per file against a comment-free printout. healthlog/no-planning-tags is enabled at error level with this commit, so the tree it lands on is clean.
34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
"use client";
|
|
|
|
import { useAuth } from "@/hooks/use-auth";
|
|
import { useQueryClientMounted } from "@/hooks/_internal/use-query-client-safe";
|
|
import type { ModuleKey } from "@/lib/modules/registry";
|
|
|
|
/**
|
|
* v1.18.0 — SSR-safe accessor for a per-account module flag.
|
|
*
|
|
* `useAuth()` calls `useQuery` directly and
|
|
* crashes when a legacy presentational component (`<HeroStrip>`, the
|
|
* isolated score-card snapshots, …) renders without a
|
|
* `<QueryClientProvider>`. We gate the inner hook on
|
|
* `useQueryClientMounted()` and short-circuit to the default-on result
|
|
* when no client is in the tree — the branch is stable across the
|
|
* component's lifetime, so the conditional call is safe per the Rules of
|
|
* Hooks.
|
|
*
|
|
* Default-on (disabled allowlist): an absent map, a missing key, or any
|
|
* non-`false` value reads as enabled — matching the server gate in
|
|
* `src/lib/modules/gate.ts`.
|
|
*/
|
|
export function useModuleEnabled(moduleKey: ModuleKey): boolean {
|
|
const hasClient = useQueryClientMounted();
|
|
if (!hasClient) return true;
|
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
return useModuleEnabledInner(moduleKey);
|
|
}
|
|
|
|
function useModuleEnabledInner(moduleKey: ModuleKey): boolean {
|
|
const { user } = useAuth();
|
|
return user?.modules?.[moduleKey] !== false;
|
|
}
|