fix(handover): show the link holder display names only

The claim preview is anonymous: whoever holds the link has proved
nothing yet. It listed each guardian's grant id and fell back to their
login name. It now carries the display name alone, null when there is
none, and the page says "a guardian" for that.

The notifications to the guardians fell back to the new owner's login
name when the record had no display name. They now use sentences about
the person the guardian looked after instead.
This commit is contained in:
Marc-André Bombeck committed 2026-10-08 22:37:57 +02:00
1 parent f71becef29
commit 055c48a3fe
16 files changed
+221 -47

No files matched your search

@@ -92,11 +92,11 @@ export const POST = apiHandler(async (request: NextRequest) => {
if (result.changed.length > 0) {
const self = await prisma.user.findUnique({
where: { id: user.id },
select: { displayName: true, username: true },
select: { displayName: true },
});
notifyGuardiansOfHandover(
"changed",
self?.displayName?.trim() || self?.username || user.username,
self?.displayName ?? null,
result.changed,
);
}
+1 -5
View File
@@ -138,11 +138,7 @@ export const POST = apiHandler(async (request: NextRequest) => {
details: { method: "password" },
});
notifyGuardiansOfHandover(
"claimed",
claimed.displayName ?? claimed.username,
claimed.guardians,
);
notifyGuardiansOfHandover("claimed", claimed.displayName, claimed.guardians);
annotate({
action: { name: "profile_claim.complete" },
+3 -3
View File
@@ -219,15 +219,15 @@ export function ClaimProfile({ token }: { token: string | null }) {
</h2>
{data.guardians.length > 0 ? (
<ul className="divide-y rounded-lg border">
{data.guardians.map((guardian) => (
{data.guardians.map((guardian, index) => (
<li
key={guardian.grantId}
key={index}
data-slot="claim-guardian"
data-proposal={guardian.proposal}
className="flex items-center justify-between gap-3 px-3 py-2"
>
<span className="min-w-0 truncate text-sm">
{guardian.displayName}
{guardian.displayName ?? t("auth.claim.guardianUnnamed")}
</span>
<span className="text-muted-foreground shrink-0 text-xs">
{accessLabel(t, guardian.proposal)}
+41 -13
View File
@@ -18,41 +18,69 @@ import { dispatchLocalisedNotification } from "@/lib/notifications/dispatch-loca
function accessMessageKey(
kind: "claimed" | "changed",
access: HandoverAccess,
named: boolean,
): string {
if (kind === "claimed") {
switch (access) {
case "end":
return "notifications.handover.claimedEnd";
return named
? "notifications.handover.claimedEnd"
: "notifications.handover.unnamed.claimedEnd";
case "read":
return "notifications.handover.claimedRead";
return named
? "notifications.handover.claimedRead"
: "notifications.handover.unnamed.claimedRead";
case "manage":
return "notifications.handover.claimedManage";
return named
? "notifications.handover.claimedManage"
: "notifications.handover.unnamed.claimedManage";
}
}
switch (access) {
case "end":
return "notifications.handover.changedEnd";
return named
? "notifications.handover.changedEnd"
: "notifications.handover.unnamed.changedEnd";
case "read":
return "notifications.handover.changedRead";
return named
? "notifications.handover.changedRead"
: "notifications.handover.unnamed.changedRead";
case "manage":
return "notifications.handover.changedManage";
return named
? "notifications.handover.changedManage"
: "notifications.handover.unnamed.changedManage";
}
}
function titleKey(kind: "claimed" | "changed", named: boolean): string {
if (kind === "claimed") {
return named
? "notifications.handover.claimedTitle"
: "notifications.handover.unnamed.claimedTitle";
}
return named
? "notifications.handover.changedTitle"
: "notifications.handover.unnamed.changedTitle";
}
/**
* `recordName` is the display name the Guardians knew the record by, or null.
* Never the login name: the new owner chose it to sign in with, and a
* notification to somebody else is no place for it. Without a display name
* the sentences speak of "the person you looked after".
*/
export function notifyGuardiansOfHandover(
kind: "claimed" | "changed",
recordName: string,
recordName: string | null,
guardians: { guardianId: string; access: HandoverAccess }[],
): void {
const name = recordName?.trim() || null;
for (const guardian of guardians) {
void dispatchLocalisedNotification({
userId: guardian.guardianId,
titleKey:
kind === "claimed"
? "notifications.handover.claimedTitle"
: "notifications.handover.changedTitle",
messageKey: accessMessageKey(kind, guardian.access),
params: { name: recordName },
titleKey: titleKey(kind, name !== null),
messageKey: accessMessageKey(kind, guardian.access, name !== null),
...(name ? { params: { name } } : {}),
}).catch((err: unknown) => {
getEvent()?.addWarning(
`handover notification failed: ${err instanceof Error ? err.message : String(err)}`,
+10 -7
View File
@@ -432,9 +432,13 @@ function isOpen(
export interface HandoverPreview {
displayName: string | null;
expiresAt: Date;
/**
* Display names only: the holder of the link has proved nothing beyond
* holding it, so no grant id and no login name (a Guardian without a
* display name is null, and the page says "a guardian").
*/
guardians: {
grantId: string;
displayName: string;
displayName: string | null;
proposal: HandoverAccess;
}[];
}
@@ -443,8 +447,8 @@ export interface HandoverPreview {
* What a link would hand over, or null for every kind of unusable link.
*
* Deliberately minimal: the profile's name, the expiry, and who keeps which
* access. No health data, no date of birth, no usernames — the person holding
* the link has not proved anything yet beyond holding it.
* access. No health data, no date of birth, no usernames and no grant ids —
* the person holding the link has not proved anything yet beyond holding it.
*/
export async function previewHandover(
rawToken: string,
@@ -468,7 +472,7 @@ export async function previewHandover(
where: { grantorId: row.profileId, ...activeGuardianWhere(now) },
select: {
id: true,
grantee: { select: { displayName: true, username: true } },
grantee: { select: { displayName: true } },
},
orderBy: { createdAt: "asc" },
});
@@ -476,8 +480,7 @@ export async function previewHandover(
displayName: profile.displayName,
expiresAt: row.expiresAt,
guardians: guardians.map((g) => ({
grantId: g.id,
displayName: nameOf(g.grantee),
displayName: g.grantee.displayName?.trim() || null,
proposal: proposalFor(state, g.id),
})),
};
+6 -2
View File
@@ -718,8 +718,12 @@ const claimPreview = z
guardians: z
.array(
z.object({
grantId: z.string(),
displayName: z.string(),
displayName: z
.string()
.nullable()
.describe(
"The guardian's display name; null when they set none. Never a login name or an id: the holder of the link has proved nothing yet.",
),
proposal: claimAccess,
}),
)
+1 -2
View File
@@ -18,8 +18,7 @@ export interface ProfileClaimPreview {
displayName: string | null;
expiresAt: string;
guardians: {
grantId: string;
displayName: string;
displayName: string | null;
proposal: HandoverAccess;
}[];
}