mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-18 08:02:12 +00:00
Privacy-leaning users want the Coach affordance gone even when the
operator has enabled the global `assistant.coach` feature flag. The
new per-user `user.disable_coach` boolean is a hard client-side gate
that sits BELOW the existing operator flag — both must agree to
render the affordance.
The toggle ships as a Switch in Settings → Insights ("Hide Coach" /
"Coach ausblenden") and persists via `PATCH /api/auth/me/disable-coach`.
Every Coach mount point on the web (`<LayoutCoachFab>`,
`<LayoutCoachMount>`, the inline `<CoachLaunchButton>` pill, the
`<SuggestedPrompts>` chip strip, the `<HeroStrip>` action row, the
`/targets` page CTAs) reads the new value through a small
SSR-safe `useDisableCoach` hook so the long-tail snapshot tests
keep rendering without a QueryClientProvider.
Default is `false` — the upgrade from v1.4.46 is invisible to anyone
who hasn't toggled the new switch. The /api/auth/me payload tolerates
an undefined field for partial-deploy rollback safety. A dedicated
invariant fixture pins every Coach surface against both the
operator-level and the per-user gates; the existing cascade test
gains a `generated/` skip so Prisma's `inlineSchema` doc-comment
copy doesn't trip the orphan check.
Bilingual + es/fr/it/pl translations land in the same commit.
43 lines
1.7 KiB
TypeScript
43 lines
1.7 KiB
TypeScript
import { apiSuccess } from "@/lib/api-response";
|
|
import { getGravatarUrl } from "@/lib/gravatar";
|
|
import { apiHandler, requireAuth } from "@/lib/api-handler";
|
|
import { annotate } from "@/lib/logging/context";
|
|
import { setOnboardingPendingCookie } from "@/lib/auth/session";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export const GET = apiHandler(async () => {
|
|
const { user } = await requireAuth();
|
|
|
|
// v1.4.22 W5 reconcile (Sr-H1) — fall-back resync for legacy
|
|
// sessions that predate the cookie. New sessions anchor the cookie
|
|
// inside `createSession` itself, so this is no longer the primary
|
|
// write path; it just makes sure pre-v1.4.22 sessions get their
|
|
// cookie set on the first /me roundtrip after the upgrade.
|
|
await setOnboardingPendingCookie(user.onboardingCompletedAt == null);
|
|
|
|
annotate({ action: { name: "auth.me" } });
|
|
|
|
return apiSuccess({
|
|
id: user.id,
|
|
username: user.username,
|
|
email: user.email,
|
|
role: user.role ?? "USER",
|
|
heightCm: user.heightCm,
|
|
dateOfBirth: user.dateOfBirth,
|
|
gender: user.gender,
|
|
timezone: user.timezone,
|
|
onboardingCompletedAt: user.onboardingCompletedAt,
|
|
onboardingTourCompleted: user.onboardingTourCompleted,
|
|
gravatarUrl: user.email ? getGravatarUrl(user.email) : null,
|
|
glucoseUnit: user.glucoseUnit ?? null,
|
|
lastReportPracticeName: user.lastReportPracticeName ?? null,
|
|
// v1.4.47 W3 — per-user Coach opt-out. Default `false` if the
|
|
// column is absent (partial-deploy rollback safety, see migration
|
|
// 0076 commentary). Every Coach mount point on the client checks
|
|
// `user.disableCoach` BELOW the operator-level `flags.coach`
|
|
// short-circuit; both gates must agree to paint the affordance.
|
|
disableCoach: user.disableCoach ?? false,
|
|
});
|
|
});
|