From 0c73cfb3c61aadac7eae1e01436db5d2e9add009 Mon Sep 17 00:00:00 2001 From: shenlan Date: Mon, 13 Oct 2025 14:14:26 +0800 Subject: [PATCH] Fix tenant normalization types and add QR code typings (#514) --- ui/homepage/app/api/auth/session/route.ts | 22 +++++++++++----------- ui/homepage/lib/userStore.tsx | 23 ++++++++++++----------- ui/homepage/types/qrcode.d.ts | 18 ++++++++++++++++++ 3 files changed, 41 insertions(+), 22 deletions(-) create mode 100644 ui/homepage/types/qrcode.d.ts diff --git a/ui/homepage/app/api/auth/session/route.ts b/ui/homepage/app/api/auth/session/route.ts index daeafd8..3202cf0 100644 --- a/ui/homepage/app/api/auth/session/route.ts +++ b/ui/homepage/app/api/auth/session/route.ts @@ -120,19 +120,19 @@ export async function GET(request: NextRequest) { return null } - const label = - typeof tenant.name === 'string' && tenant.name.trim().length > 0 - ? tenant.name.trim() - : undefined - const roleValue = - typeof tenant.role === 'string' && tenant.role.trim().length > 0 - ? tenant.role.trim().toLowerCase() - : undefined - return { + const normalizedTenant: { id: string; name?: string; role?: string } = { id: identifier, - name: label, - role: roleValue, } + + if (typeof tenant.name === 'string' && tenant.name.trim().length > 0) { + normalizedTenant.name = tenant.name.trim() + } + + if (typeof tenant.role === 'string' && tenant.role.trim().length > 0) { + normalizedTenant.role = tenant.role.trim().toLowerCase() + } + + return normalizedTenant }) .filter((tenant): tenant is { id: string; name?: string; role?: string } => Boolean(tenant)) : undefined diff --git a/ui/homepage/lib/userStore.tsx b/ui/homepage/lib/userStore.tsx index ce406e8..0416419 100644 --- a/ui/homepage/lib/userStore.tsx +++ b/ui/homepage/lib/userStore.tsx @@ -187,19 +187,20 @@ async function fetchSessionUser(): Promise { if (!identifier) { return null } - const label = - typeof tenant.name === 'string' && tenant.name.trim().length > 0 - ? tenant.name.trim() - : undefined - const roleValue = - typeof tenant.role === 'string' && tenant.role.trim().length > 0 - ? normalizeRole(tenant.role) - : undefined - return { + + const normalizedTenant: TenantMembership = { id: identifier, - name: label, - role: roleValue, } + + if (typeof tenant.name === 'string' && tenant.name.trim().length > 0) { + normalizedTenant.name = tenant.name.trim() + } + + if (typeof tenant.role === 'string' && tenant.role.trim().length > 0) { + normalizedTenant.role = normalizeRole(tenant.role) + } + + return normalizedTenant }) .filter((tenant): tenant is TenantMembership => Boolean(tenant)) : undefined diff --git a/ui/homepage/types/qrcode.d.ts b/ui/homepage/types/qrcode.d.ts new file mode 100644 index 0000000..178fc87 --- /dev/null +++ b/ui/homepage/types/qrcode.d.ts @@ -0,0 +1,18 @@ +declare module 'qrcode' { + export type ErrorCorrectionLevel = 'L' | 'M' | 'Q' | 'H' + + export type QRCodeColorOptions = { + dark?: string + light?: string + } + + export type QRCodeToDataURLOptions = { + errorCorrectionLevel?: ErrorCorrectionLevel + margin?: number + scale?: number + width?: number + color?: QRCodeColorOptions + } + + export function toDataURL(text: string, options?: QRCodeToDataURLOptions): Promise +}