mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 23:33:29 +00:00
fix(profile): one display-name bound, checked after trimming
The setup flow capped a display name at 50 characters while the profile took 80, and the profile checked its minimum before trimming, so a name of only spaces was stored as an empty string. Every surface now reads one bound (80), the profile trims before validating, and only spaces means no name on both paths: the profile clears it to null, the setup flow leaves it unset.
This commit is contained in:
1 parent
a264dee030
commit
03cacc996c
11 files changed
+93
-11
No files matched your search
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* The one bound on a display name, for every surface that sets one: the setup
|
||||
* flow, the profile (web and native), and a managed profile. The setup flow
|
||||
* used to cap it at 50 while the profile took 80, so a name set later could
|
||||
* not be typed into the setup form of another device.
|
||||
*/
|
||||
import { z } from "zod/v4";
|
||||
|
||||
export const DISPLAY_NAME_MAX_LENGTH = 80;
|
||||
|
||||
/**
|
||||
* An optional display name: trimmed BEFORE its bounds are checked, so a value
|
||||
* of only spaces is the empty string, which every writer stores as "no name"
|
||||
* (null). It used to be checked untrimmed and trimmed after, which stored an
|
||||
* empty name for " ".
|
||||
*/
|
||||
export const optionalDisplayNameSchema = z
|
||||
.string()
|
||||
.trim()
|
||||
.max(DISPLAY_NAME_MAX_LENGTH);
|
||||
@@ -10,6 +10,7 @@
|
||||
* refused rather than ignored — and the client types name exactly these fields
|
||||
* for the same reason (`src/lib/queries/use-managed-profiles.ts`).
|
||||
*/
|
||||
import { DISPLAY_NAME_MAX_LENGTH } from "@/lib/validations/display-name";
|
||||
import { z } from "zod/v4";
|
||||
|
||||
import { isValidTimezone } from "@/lib/tz/format";
|
||||
@@ -30,7 +31,7 @@ const managedProfileGenderSchema = z.enum(["MALE", "FEMALE", "OTHER"]);
|
||||
|
||||
/** The fields both bodies below share, with their bounds stated once. */
|
||||
const managedProfileFields = {
|
||||
displayName: z.string().trim().min(1).max(80),
|
||||
displayName: z.string().trim().min(1).max(DISPLAY_NAME_MAX_LENGTH),
|
||||
dateOfBirth: z.iso.date().nullable(),
|
||||
locale: z.enum(["de", "en", "es", "fr", "it", "pl", "ko", "nl"]),
|
||||
timezone: z
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
* Prisma-free by construction, so the generator script can pull it in
|
||||
* without dragging the server graph along.
|
||||
*/
|
||||
import { optionalDisplayNameSchema } from "@/lib/validations/display-name";
|
||||
import { z } from "zod/v4";
|
||||
|
||||
/**
|
||||
@@ -41,7 +42,8 @@ export const onboardingCompleteSchema = z.object({
|
||||
.describe(
|
||||
"The managed record the setup answers were given FOR — the profile \"someone I look after\" created on the confirm screen. When present, the module map and the dashboard order derived from the caller's answers are applied to THAT record and its own setup row is written as finished; the caller's own record is stamped complete and its derivation latched without any module being touched. Honoured only for a managed profile the caller actively guards (otherwise 404 `onboarding.complete.recordNotFound`) and only when the answer to Q1 was `someone-else` (otherwise 422 `onboarding.complete.recordTargetMismatch`); nothing is stamped on a refusal. Absent with Q1 = `someone-else`, the flow completes without deriving anything anywhere.",
|
||||
),
|
||||
displayName: z.string().trim().min(1).max(50).optional(),
|
||||
// Only spaces is no name: trimmed to "", which the route leaves unset.
|
||||
displayName: optionalDisplayNameSchema.optional(),
|
||||
heightCm: z.number().min(50).max(300).optional(),
|
||||
dateOfBirth: z.string().optional(),
|
||||
// The same three values the profile schema stores. A narrower enum here
|
||||
|
||||
Reference in new issue
Block a user