Skip to content

Commit 0b514ec

Browse files
feat(citizen-portal-web): resolve displayName from display_name claim (#29)
Align the browser-side displayName() helper with the citizen-portal-api mapClaims change: prefer display_name, then email, then the opaque user id (name/preferred_username are no longer used). Declare display_name on the local OidcClaims mirror and update the landing fixture to exercise the new path.
1 parent 7ee1ada commit 0b514ec

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

apps/citizen-portal-web/src/lib/bff.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
export interface OidcClaims {
1010
sub: string;
1111
email?: string;
12+
/** Citizen realm's preferred display label (see `keycloak/citizens-realm.json` mapper). */
13+
display_name?: string;
1214
name?: string;
1315
preferred_username?: string;
1416
[claim: string]: unknown;
@@ -59,7 +61,11 @@ export async function logout(): Promise<void> {
5961
await fetch(`${BFF_ORIGIN}/auth/logout`, { method: 'POST', credentials: 'include' });
6062
}
6163

62-
/** Best-effort greeting label: display name → username → email → opaque id. */
64+
/**
65+
* Best-effort greeting label: display name → email → opaque id. Mirrors the citizen-portal-api
66+
* `mapClaims` order (`display_name ?? email ?? sub`); `user.id` is the always-present final
67+
* fallback here (the browser never sees a bare `sub`).
68+
*/
6369
export function displayName(user: AuthUser): string {
64-
return user.claims.name ?? user.claims.preferred_username ?? user.claims.email ?? user.id;
70+
return user.claims.display_name ?? user.claims.email ?? user.id;
6571
}

apps/citizen-portal-web/test/landing.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { routeTree } from '@/routeTree.gen';
88
const authedUser = {
99
id: 'c1',
1010
roles: ['citizen'],
11-
claims: { sub: 'subject-1', preferred_username: 'citizen1', name: 'Amina Ali' },
11+
claims: { sub: 'subject-1', preferred_username: 'citizen1', display_name: 'Amina Ali' },
1212
};
1313

1414
const services = [

0 commit comments

Comments
 (0)