From 04b6f7de3fc32557f6764fa0f9ad667e095eb009 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 6 Jan 2026 19:43:58 +0000 Subject: [PATCH] Address code review feedback - use spread operator, fix path parsing logic, remove non-null assertion Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com> --- frontends/nextjs/src/lib/routing/index.ts | 7 ++----- frontends/nextjs/src/lib/routing/route-parser.ts | 9 +++++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/frontends/nextjs/src/lib/routing/index.ts b/frontends/nextjs/src/lib/routing/index.ts index 77b3200db..d2ea7843e 100644 --- a/frontends/nextjs/src/lib/routing/index.ts +++ b/frontends/nextjs/src/lib/routing/index.ts @@ -78,14 +78,11 @@ export async function getSessionUser(_req?: Request): Promise { } // Convert User to Record for compatibility + // Use spread operator for maintainability return { user: { - id: user.id, - username: user.username, - email: user.email, - role: user.role, + ...user, tenantId: user.tenantId ?? null, - createdAt: user.createdAt, profilePicture: user.profilePicture ?? null, bio: user.bio ?? null, isInstanceOwner: user.isInstanceOwner ?? false, diff --git a/frontends/nextjs/src/lib/routing/route-parser.ts b/frontends/nextjs/src/lib/routing/route-parser.ts index f965cf6a2..2e57026e1 100644 --- a/frontends/nextjs/src/lib/routing/route-parser.ts +++ b/frontends/nextjs/src/lib/routing/route-parser.ts @@ -30,9 +30,9 @@ export function parseRoute(url: string): ParsedRoute { // Try to extract tenant/package/path from segments // Pattern: /{tenant}/{package}/...rest - if (segments.length >= 1) { + if (segments.length >= 1 && segments[0] !== undefined) { const firstSegment = segments[0] - if (firstSegment !== undefined && !isReservedPath(firstSegment)) { + if (!isReservedPath(firstSegment)) { result.tenant = firstSegment } } @@ -66,8 +66,9 @@ export function getTableName(entity: string, tenantId?: string): string { } export function isReservedPath(path: string): boolean { - // Get the first segment of the path - const segment = path.startsWith('/') ? path.split('/')[1] : path.split('/')[0] + // Normalize path to get the first segment + const normalizedPath = path.startsWith('/') ? path.slice(1) : path + const segment = normalizedPath.split('/')[0] // Check if the segment matches any reserved paths return segment !== undefined && RESERVED_PATHS.includes(segment)