From f278e1b069b395349e005febe7aa955be664c0c4 Mon Sep 17 00:00:00 2001 From: Claudio Fuentes Date: Thu, 31 Jul 2025 22:49:25 -0400 Subject: [PATCH 1/6] refactor: remove baseURL from authClient configuration - Eliminated the baseURL property from the authClient setup, streamlining the authentication client configuration. - This change may improve flexibility in handling authentication URLs based on different environments. --- apps/app/src/utils/auth-client.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/app/src/utils/auth-client.ts b/apps/app/src/utils/auth-client.ts index f2ff4725a..5919c87fd 100644 --- a/apps/app/src/utils/auth-client.ts +++ b/apps/app/src/utils/auth-client.ts @@ -9,7 +9,6 @@ import { auth } from './auth'; import { ac, allRoles } from './permissions'; export const authClient = createAuthClient({ - baseURL: process.env.NEXT_PUBLIC_BETTER_AUTH_URL, plugins: [ organizationClient({ ac, From 5a74e07ced1e26d95b99a3835a8183877884408a Mon Sep 17 00:00:00 2001 From: Claudio Fuentes Date: Thu, 31 Jul 2025 22:50:25 -0400 Subject: [PATCH 2/6] refactor: add staging origin to trustedOrigins in auth configuration - Updated the trustedOrigins array in the auth configuration to include the new staging URL, enhancing environment-specific authentication handling. - This change allows for better management of authentication requests across different deployment environments. --- apps/app/src/utils/auth.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/app/src/utils/auth.ts b/apps/app/src/utils/auth.ts index 0c36f2912..e8899c64f 100644 --- a/apps/app/src/utils/auth.ts +++ b/apps/app/src/utils/auth.ts @@ -45,7 +45,11 @@ export const auth = betterAuth({ database: prismaAdapter(db, { provider: 'postgresql', }), - trustedOrigins: ['http://localhost:3000', 'https://app.trycomp.ai', 'https://dev.trycomp.ai'], + trustedOrigins: [ + 'http://localhost:3000', + 'https://app.trycomp.ai', + 'https://app.staging.trycomp.ai', + ], emailAndPassword: { enabled: true, }, From 22cf81a46f7b89578b670497bd7b63e5ac01f42f Mon Sep 17 00:00:00 2001 From: Claudio Fuentes Date: Thu, 31 Jul 2025 22:58:26 -0400 Subject: [PATCH 3/6] refactor: enhance logging in upload-file and S3 modules - Added detailed console log statements in the upload-file and S3 modules to improve traceability during module loading and import processes. - Included the baseURL in the auth configuration to ensure proper handling of authentication requests across different environments. --- apps/app/src/actions/files/upload-file.ts | 18 ++++++++++++++---- apps/app/src/app/s3.ts | 2 ++ apps/app/src/utils/auth.ts | 1 + 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/apps/app/src/actions/files/upload-file.ts b/apps/app/src/actions/files/upload-file.ts index d20b46d2c..98b197e33 100644 --- a/apps/app/src/actions/files/upload-file.ts +++ b/apps/app/src/actions/files/upload-file.ts @@ -1,12 +1,11 @@ 'use server'; +console.log('[uploadFile] Upload action module is being loaded...'); + +console.log('[uploadFile] Importing auth and logger...'); import { BUCKET_NAME, s3Client } from '@/app/s3'; import { auth } from '@/utils/auth'; import { logger } from '@/utils/logger'; - -// This log will run as soon as the module is loaded. -logger.info('[uploadFile] Module loaded.'); - import { GetObjectCommand, PutObjectCommand } from '@aws-sdk/client-s3'; import { getSignedUrl } from '@aws-sdk/s3-request-presigner'; import { AttachmentEntityType, AttachmentType, db } from '@db'; @@ -14,6 +13,17 @@ import { revalidatePath } from 'next/cache'; import { headers } from 'next/headers'; import { z } from 'zod'; +console.log('[uploadFile] Importing S3 client...'); + +console.log('[uploadFile] Importing AWS SDK...'); + +console.log('[uploadFile] Importing database...'); + +console.log('[uploadFile] All imports successful'); + +// This log will run as soon as the module is loaded. +logger.info('[uploadFile] Module loaded.'); + function mapFileTypeToAttachmentType(fileType: string): AttachmentType { const type = fileType.split('/')[0]; switch (type) { diff --git a/apps/app/src/app/s3.ts b/apps/app/src/app/s3.ts index fd6ddb3d2..1a4a5ca10 100644 --- a/apps/app/src/app/s3.ts +++ b/apps/app/src/app/s3.ts @@ -1,5 +1,7 @@ import { GetObjectCommand, S3Client } from '@aws-sdk/client-s3'; +console.log('[S3] S3 module is being loaded...'); + const APP_AWS_REGION = process.env.APP_AWS_REGION; const APP_AWS_ACCESS_KEY_ID = process.env.APP_AWS_ACCESS_KEY_ID; const APP_AWS_SECRET_ACCESS_KEY = process.env.APP_AWS_SECRET_ACCESS_KEY; diff --git a/apps/app/src/utils/auth.ts b/apps/app/src/utils/auth.ts index e8899c64f..1eef56bc1 100644 --- a/apps/app/src/utils/auth.ts +++ b/apps/app/src/utils/auth.ts @@ -45,6 +45,7 @@ export const auth = betterAuth({ database: prismaAdapter(db, { provider: 'postgresql', }), + baseURL: process.env.BETTER_AUTH_URL, trustedOrigins: [ 'http://localhost:3000', 'https://app.trycomp.ai', From c92c2c3575632ae11533faca551327a5d3c62da1 Mon Sep 17 00:00:00 2001 From: Claudio Fuentes Date: Thu, 31 Jul 2025 23:07:20 -0400 Subject: [PATCH 4/6] refactor: improve logging and configuration in upload-file and auth-client - Added console log statements in the uploadFile function to enhance traceability during execution, including checks for S3 client availability and input parsing. - Configured the authClient to use the baseURL from environment variables, ensuring proper authentication handling across different environments. --- apps/app/src/actions/files/upload-file.ts | 6 ++++++ apps/app/src/utils/auth-client.ts | 1 + 2 files changed, 7 insertions(+) diff --git a/apps/app/src/actions/files/upload-file.ts b/apps/app/src/actions/files/upload-file.ts index 98b197e33..e4f90ff1e 100644 --- a/apps/app/src/actions/files/upload-file.ts +++ b/apps/app/src/actions/files/upload-file.ts @@ -50,7 +50,10 @@ const uploadAttachmentSchema = z.object({ }); export const uploadFile = async (input: z.infer) => { + console.log('[uploadFile] Function called - starting execution'); logger.info(`[uploadFile] Starting upload for ${input.fileName}`); + + console.log('[uploadFile] Checking S3 client availability'); try { // Check if S3 client is available if (!s3Client) { @@ -69,9 +72,11 @@ export const uploadFile = async (input: z.infer) } as const; } + console.log('[uploadFile] Parsing input schema'); const { fileName, fileType, fileData, entityId, entityType, pathToRevalidate } = uploadAttachmentSchema.parse(input); + console.log('[uploadFile] Getting user session'); const session = await auth.api.getSession({ headers: await headers() }); const organizationId = session?.session.activeOrganizationId; @@ -85,6 +90,7 @@ export const uploadFile = async (input: z.infer) logger.info(`[uploadFile] Starting upload for ${fileName} in org ${organizationId}`); + console.log('[uploadFile] Converting file data to buffer'); const fileBuffer = Buffer.from(fileData, 'base64'); const MAX_FILE_SIZE_MB = 10; diff --git a/apps/app/src/utils/auth-client.ts b/apps/app/src/utils/auth-client.ts index 5919c87fd..f2ff4725a 100644 --- a/apps/app/src/utils/auth-client.ts +++ b/apps/app/src/utils/auth-client.ts @@ -9,6 +9,7 @@ import { auth } from './auth'; import { ac, allRoles } from './permissions'; export const authClient = createAuthClient({ + baseURL: process.env.NEXT_PUBLIC_BETTER_AUTH_URL, plugins: [ organizationClient({ ac, From 163f32e1900c0f1dc58ac800fc770ef3f4e710a3 Mon Sep 17 00:00:00 2001 From: Claudio Fuentes Date: Thu, 31 Jul 2025 23:20:20 -0400 Subject: [PATCH 5/6] refactor: remove access logging from middleware - Eliminated the console log statement that checked access for organizations in the middleware, streamlining the logging process and reducing unnecessary output. --- apps/app/src/middleware.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/app/src/middleware.ts b/apps/app/src/middleware.ts index 8e27ab330..d1a7adda0 100644 --- a/apps/app/src/middleware.ts +++ b/apps/app/src/middleware.ts @@ -110,8 +110,6 @@ export async function middleware(request: NextRequest) { const hasAccess = foundOrg?.hasAccess; - console.log(`[MIDDLEWARE] Checking access for org ${orgId}: ${hasAccess}`); - if (!hasAccess) { const url = new URL(`/upgrade/${orgId}`, request.url); // Preserve existing search params From d2e3e32b456f883b5b13d0b01cfd80b133fccd0e Mon Sep 17 00:00:00 2001 From: Claudio Fuentes Date: Thu, 31 Jul 2025 23:22:10 -0400 Subject: [PATCH 6/6] refactor: enhance logging in TaskPage component - Added console log statements to track the rendering process, parameter extraction, session retrieval, and data fetching in the TaskPage component, improving traceability during execution. --- apps/app/src/app/(app)/[orgId]/tasks/[taskId]/page.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/app/src/app/(app)/[orgId]/tasks/[taskId]/page.tsx b/apps/app/src/app/(app)/[orgId]/tasks/[taskId]/page.tsx index 8028907a4..7918eaedf 100644 --- a/apps/app/src/app/(app)/[orgId]/tasks/[taskId]/page.tsx +++ b/apps/app/src/app/(app)/[orgId]/tasks/[taskId]/page.tsx @@ -13,10 +13,14 @@ export default async function TaskPage({ }: { params: Promise<{ taskId: string; orgId: string; locale: string }>; }) { + console.log('[TaskPage] Starting page render'); const { taskId, orgId } = await params; + console.log('[TaskPage] Params extracted:', { taskId, orgId }); + console.log('[TaskPage] Getting session'); const session = await auth.api.getSession({ headers: headers(), }); + console.log('[TaskPage] Session obtained, fetching data'); const [task, members, comments, attachments] = await Promise.all([ getTask(taskId, session),