## What was done: ✅ Fixed Firebase Admin initialization to use default credentials for Firebase Functions ✅ Updated frontend to use correct Firebase Functions URL (was using Cloud Run URL) ✅ Added comprehensive debugging to authentication middleware ✅ Added debugging to file upload middleware and CORS handling ✅ Added debug buttons to frontend for troubleshooting authentication ✅ Enhanced error handling and logging throughout the stack ## Current issues: ❌ Document upload still returns 400 Bad Request despite authentication working ❌ GET requests work fine (200 OK) but POST upload requests fail ❌ Frontend authentication is working correctly (valid JWT tokens) ❌ Backend authentication middleware is working (rejects invalid tokens) ❌ CORS is configured correctly and allowing requests ## Root cause analysis: - Authentication is NOT the issue (tokens are valid, GET requests work) - The problem appears to be in the file upload handling or multer configuration - Request reaches the server but fails during upload processing - Need to identify exactly where in the upload pipeline the failure occurs ## TODO next steps: 1. 🔍 Check Firebase Functions logs after next upload attempt to see debugging output 2. 🔍 Verify if request reaches upload middleware (look for '�� Upload middleware called' logs) 3. 🔍 Check if file validation is triggered (look for '🔍 File filter called' logs) 4. 🔍 Identify specific error in upload pipeline (multer, file processing, etc.) 5. 🔍 Test with smaller file or different file type to isolate issue 6. 🔍 Check if issue is with Firebase Functions file size limits or timeout 7. 🔍 Verify multer configuration and file handling in Firebase Functions environment ## Technical details: - Frontend: https://cim-summarizer.web.app - Backend: https://us-central1-cim-summarizer.cloudfunctions.net/api - Authentication: Firebase Auth with JWT tokens (working correctly) - File upload: Multer with memory storage for immediate GCS upload - Debug buttons available in production frontend for troubleshooting
88 lines
3.2 KiB
JavaScript
88 lines
3.2 KiB
JavaScript
const { createClient } = require('@supabase/supabase-js');
|
||
|
||
// Supabase configuration from environment
|
||
const SUPABASE_URL = 'https://gzoclmbqmgmpuhufbnhy.supabase.co';
|
||
const SUPABASE_SERVICE_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imd6b2NsbWJxbWdtcHVodWZibmh5Iiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTc1MzgxNjY3OCwiZXhwIjoyMDY5MzkyNjc4fQ.f9PUzL1F8JqIkqD_DwrGBIyHPcehMo-97jXD8hee5ss';
|
||
|
||
const serviceClient = createClient(SUPABASE_URL, SUPABASE_SERVICE_KEY);
|
||
|
||
async function testDatabaseWorking() {
|
||
console.log('🔍 Testing essential database functionality...\n');
|
||
|
||
try {
|
||
// Test 1: Users table
|
||
console.log('1️⃣ Testing users table...');
|
||
const { data: usersData, error: usersError } = await serviceClient
|
||
.from('users')
|
||
.select('*')
|
||
.limit(1);
|
||
|
||
if (usersError) {
|
||
console.log(`❌ Users table error: ${usersError.message}`);
|
||
} else {
|
||
console.log(`✅ Users table working! Found ${usersData?.length || 0} users`);
|
||
}
|
||
|
||
// Test 2: Documents table
|
||
console.log('\n2️⃣ Testing documents table...');
|
||
const { data: docsData, error: docsError } = await serviceClient
|
||
.from('documents')
|
||
.select('*')
|
||
.limit(1);
|
||
|
||
if (docsError) {
|
||
console.log(`❌ Documents table error: ${docsError.message}`);
|
||
} else {
|
||
console.log(`✅ Documents table working! Found ${docsData?.length || 0} documents`);
|
||
}
|
||
|
||
// Test 3: Document versions table
|
||
console.log('\n3️⃣ Testing document_versions table...');
|
||
const { data: versionsData, error: versionsError } = await serviceClient
|
||
.from('document_versions')
|
||
.select('*')
|
||
.limit(1);
|
||
|
||
if (versionsError) {
|
||
console.log(`❌ Document versions table error: ${versionsError.message}`);
|
||
} else {
|
||
console.log(`✅ Document versions table working! Found ${versionsData?.length || 0} versions`);
|
||
}
|
||
|
||
// Test 4: Document feedback table
|
||
console.log('\n4️⃣ Testing document_feedback table...');
|
||
const { data: feedbackData, error: feedbackError } = await serviceClient
|
||
.from('document_feedback')
|
||
.select('*')
|
||
.limit(1);
|
||
|
||
if (feedbackError) {
|
||
console.log(`❌ Document feedback table error: ${feedbackError.message}`);
|
||
} else {
|
||
console.log(`✅ Document feedback table working! Found ${feedbackData?.length || 0} feedback entries`);
|
||
}
|
||
|
||
// Test 5: Processing jobs table
|
||
console.log('\n5️⃣ Testing processing_jobs table...');
|
||
const { data: jobsData, error: jobsError } = await serviceClient
|
||
.from('processing_jobs')
|
||
.select('*')
|
||
.limit(1);
|
||
|
||
if (jobsError) {
|
||
console.log(`❌ Processing jobs table error: ${jobsError.message}`);
|
||
} else {
|
||
console.log(`✅ Processing jobs table working! Found ${jobsData?.length || 0} jobs`);
|
||
}
|
||
|
||
console.log('\n🎉 Database functionality test completed!');
|
||
console.log('📋 All essential tables are working correctly.');
|
||
console.log('🚀 The application should now function without 500 errors.');
|
||
|
||
} catch (error) {
|
||
console.error('❌ Database test failed:', error.message);
|
||
console.error('Error details:', error);
|
||
}
|
||
}
|
||
|
||
testDatabaseWorking();
|