From 55eaa353bf7210300a8bb9d5d4aa7eac1cfd78e1 Mon Sep 17 00:00:00 2001 From: Neil Raina Date: Wed, 6 Aug 2025 11:31:16 -0400 Subject: [PATCH] fix: handle internal user preview mode before validating clientId/companyId MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When internalUserId is provided in the token payload, the user is viewing company or client details pages that don't support preview. This should show the "CRM preview is not available" message instead of throwing an error about missing clientId or companyId. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/app/client-preview/page.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/app/client-preview/page.tsx b/src/app/client-preview/page.tsx index d01ec63..8c667a5 100644 --- a/src/app/client-preview/page.tsx +++ b/src/app/client-preview/page.tsx @@ -60,13 +60,17 @@ export default async function ClientPreviewPage({ const token = tokenParsed.data const copilotClient = new CopilotAPI(token) const tokenPayload = await copilotClient.getTokenPayload() - if (!tokenPayload || !tokenPayload.clientId || !tokenPayload.companyId) { + if (!tokenPayload) { console.info('Failing token payload', tokenPayload) throw new Error('Failed to parse token payload') } if (getPreviewMode(tokenPayload)) { return } + if (!tokenPayload.clientId || !tokenPayload.companyId) { + console.info('Missing clientId or companyId in token payload', tokenPayload) + throw new Error('Failed to parse token payload') + } const clientId = z.string().uuid().parse(tokenPayload.clientId)