Skip to content
24 changes: 20 additions & 4 deletions apps/app/src/actions/files/upload-file.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
'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';
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) {
Expand All @@ -40,7 +50,10 @@ const uploadAttachmentSchema = z.object({
});

export const uploadFile = async (input: z.infer<typeof uploadAttachmentSchema>) => {
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) {
Expand All @@ -59,9 +72,11 @@ export const uploadFile = async (input: z.infer<typeof uploadAttachmentSchema>)
} 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;

Expand All @@ -75,6 +90,7 @@ export const uploadFile = async (input: z.infer<typeof uploadAttachmentSchema>)

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;
Expand Down
4 changes: 4 additions & 0 deletions apps/app/src/app/(app)/[orgId]/tasks/[taskId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions apps/app/src/app/s3.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 0 additions & 2 deletions apps/app/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion apps/app/src/utils/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ export const auth = betterAuth({
database: prismaAdapter(db, {
provider: 'postgresql',
}),
trustedOrigins: ['http://localhost:3000', 'https://app.trycomp.ai', 'https://dev.trycomp.ai'],
baseURL: process.env.BETTER_AUTH_URL,
trustedOrigins: [
'http://localhost:3000',
'https://app.trycomp.ai',
'https://app.staging.trycomp.ai',
],
emailAndPassword: {
enabled: true,
},
Expand Down
Loading