From d71e49e2f25d586145ee15cd33889ee79da5a83c Mon Sep 17 00:00:00 2001 From: chronark Date: Wed, 29 Jan 2025 17:15:03 +0100 Subject: [PATCH] feat: use identity.externalId first, then fall back to ownerId --- .../apis/[apiId]/keys/[keyAuthId]/keys.tsx | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/keys.tsx b/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/keys.tsx index 03229c421..a50de1652 100644 --- a/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/keys.tsx +++ b/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/keys.tsx @@ -20,6 +20,11 @@ export const Keys: React.FC = async ({ keyAuthId, apiId }) => { and(eq(table.keyAuthId, keyAuthId), isNull(table.deletedAt)), limit: 100, with: { + identity: { + columns: { + externalId: true, + }, + }, roles: { with: { role: { @@ -33,9 +38,9 @@ export const Keys: React.FC = async ({ keyAuthId, apiId }) => { }, }); - const nullOwnerId = "UNKEY_NULL_OWNER_ID"; + const nullExternalId = "UNKEY_NULL_OWNER_ID"; type KeysByOwnerId = { - [ownerId: string]: { + [externalId: string]: { id: string; keyAuthId: string; name: string | null; @@ -46,10 +51,10 @@ export const Keys: React.FC = async ({ keyAuthId, apiId }) => { environment: string | null; }[]; }; - const keysByOwnerId = keys.reduce((acc, curr) => { - const ownerId = curr.ownerId ?? nullOwnerId; - if (!acc[ownerId]) { - acc[ownerId] = []; + const keysByExternalId = keys.reduce((acc, curr) => { + const externalId = curr.identity?.externalId ?? curr.ownerId ?? nullExternalId; + if (!acc[externalId]) { + acc[externalId] = []; } const permissions = new Set(curr.permissions.map((p) => p.permissionId)); for (const role of curr.roles) { @@ -57,7 +62,7 @@ export const Keys: React.FC = async ({ keyAuthId, apiId }) => { permissions.add(permission.permissionId); } } - acc[ownerId].push({ + acc[externalId].push({ id: curr.id, keyAuthId: curr.keyAuthId, name: curr.name, @@ -85,10 +90,10 @@ export const Keys: React.FC = async ({ keyAuthId, apiId }) => { {/* Create New Role} /> */} ) : ( - Object.entries(keysByOwnerId).map(([ownerId, ks]) => ( + Object.entries(keysByExternalId).map(([externalId, ks]) => (
- {ownerId === nullOwnerId ? ( + {externalId === nullExternalId ? (
Without OwnerID @@ -103,7 +108,7 @@ export const Keys: React.FC = async ({ keyAuthId, apiId }) => { className="flex items-center justify-between gap-2 text-xs font-medium ph-no-capture" > - {ownerId} + {externalId}
)}