mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 15:42:24 +00:00
feat(onboarding): one-time medical-disclaimer acknowledgment
Replace the per-page and per-chart disclaimer banners with a single acknowledgment at the start of onboarding: HealthLog is a private tracking tool, not a clinical assessment or diagnosis; talk to a doctor if worried. - record the acknowledgment per user (disclaimer_acknowledged_at/_version, migration 0175) mirroring the research-mode acknowledgment precedent - gate the welcome "Get started" on the checkbox; expose the timestamp on /api/auth/me so a returning user is never re-asked - keep the full legal text reachable on the public privacy page
This commit is contained in:
1 parent
267dcad13d
commit
0a8ccaa30c
7 files changed
+162
-2
No files matched your search
@@ -71,6 +71,10 @@ export const GET = apiHandler(async () => {
|
||||
timezone: user.timezone,
|
||||
onboardingCompletedAt: user.onboardingCompletedAt,
|
||||
onboardingTourCompleted: user.onboardingTourCompleted,
|
||||
// v1.18.6 (DISC-02) — one-time medical-disclaimer acknowledgment. Null
|
||||
// when never acknowledged; the onboarding welcome gate reads this to
|
||||
// decide whether to require the acknowledgment before "Get started".
|
||||
disclaimerAcknowledgedAt: user.disclaimerAcknowledgedAt,
|
||||
// v1.18.6 — resumable module-tour progress. Null when the user has
|
||||
// not started the tour; otherwise the resume point the launcher
|
||||
// seeds its index from. Fail-soft parse: a corrupt blob degrades to
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import { z } from "zod/v4";
|
||||
|
||||
import { prisma } from "@/lib/db";
|
||||
import { apiHandler, requireAuth } from "@/lib/api-handler";
|
||||
import { annotate } from "@/lib/logging/context";
|
||||
import { apiSuccess, apiError, safeJson } from "@/lib/api-response";
|
||||
import { DISCLAIMER_VERSION } from "@/lib/onboarding/disclaimer";
|
||||
|
||||
/**
|
||||
* v1.18.6 (DISC-02) — one-time medical-disclaimer acknowledgment.
|
||||
*
|
||||
* POST { version: string }
|
||||
* → stamps `users.disclaimer_acknowledged_at = now()` +
|
||||
* `disclaimer_acknowledged_version = <version>`. Idempotent: a repeat
|
||||
* acknowledgment of the same version simply refreshes the timestamp.
|
||||
*
|
||||
* Replaces the per-page / per-chart disclaimer banners removed app-wide in
|
||||
* the same release. The acknowledged legal text stays reachable on the public
|
||||
* privacy page. Never auto-set; the onboarding welcome step is the one writer.
|
||||
*/
|
||||
|
||||
const bodySchema = z.object({
|
||||
// Echoed back from the client so a stale shell cannot silently record an
|
||||
// acknowledgment of copy it never rendered. Bounded; the server pins the
|
||||
// canonical version it persists regardless.
|
||||
version: z.string().min(1).max(64),
|
||||
});
|
||||
|
||||
export const POST = apiHandler(async (request) => {
|
||||
const { user } = await requireAuth();
|
||||
|
||||
const { data: rawBody, error: jsonError } = await safeJson(request, {
|
||||
maxBytes: 4 * 1024,
|
||||
});
|
||||
if (jsonError) return jsonError;
|
||||
|
||||
const parsed = z.safeParse(bodySchema, rawBody);
|
||||
if (!parsed.success) {
|
||||
return apiError("Invalid input", 422);
|
||||
}
|
||||
|
||||
// The server pins the canonical version it stamps — the body version is
|
||||
// only a freshness signal, never the source of truth.
|
||||
await prisma.user.update({
|
||||
where: { id: user.id },
|
||||
data: {
|
||||
disclaimerAcknowledgedAt: new Date(),
|
||||
disclaimerAcknowledgedVersion: DISCLAIMER_VERSION,
|
||||
},
|
||||
});
|
||||
|
||||
annotate({
|
||||
action: { name: "onboarding.disclaimer.acknowledge" },
|
||||
meta: {
|
||||
version: DISCLAIMER_VERSION,
|
||||
clientVersion: parsed.data.version,
|
||||
},
|
||||
});
|
||||
|
||||
return apiSuccess({ acknowledgedVersion: DISCLAIMER_VERSION });
|
||||
});
|
||||
Reference in new issue
Block a user