🔧 Fix authentication and document upload issues

## 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
This commit is contained in:
Jon
2025-07-31 16:18:53 -04:00
parent aa0931ecd7
commit 6057d1d7fd
79 changed files with 8920 additions and 1786 deletions

View File

@@ -1,47 +1,43 @@
# Backend Environment Variables
# Backend Environment Variables - Cloud-Only Configuration
# Server Configuration
PORT=5000
# App Configuration
NODE_ENV=development
PORT=5000
# Database Configuration
DATABASE_URL=postgresql://username:password@localhost:5432/cim_processor
DB_HOST=localhost
DB_PORT=5432
DB_NAME=cim_processor
DB_USER=username
DB_PASSWORD=password
# Supabase Configuration (Required)
SUPABASE_URL=your-supabase-project-url
SUPABASE_ANON_KEY=your-supabase-anon-key
SUPABASE_SERVICE_KEY=your-supabase-service-key
# Redis Configuration
REDIS_URL=redis://localhost:6379
REDIS_HOST=localhost
REDIS_PORT=6379
# JWT Configuration
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
JWT_EXPIRES_IN=1h
JWT_REFRESH_SECRET=your-super-secret-refresh-key-change-this-in-production
JWT_REFRESH_EXPIRES_IN=7d
# File Upload Configuration
MAX_FILE_SIZE=104857600
UPLOAD_DIR=uploads
ALLOWED_FILE_TYPES=application/pdf
# Vector Database Configuration
VECTOR_PROVIDER=supabase
# LLM Configuration
LLM_PROVIDER=openai
OPENAI_API_KEY=your-openai-api-key
LLM_PROVIDER=anthropic
ANTHROPIC_API_KEY=your-anthropic-api-key
LLM_MODEL=gpt-4
OPENAI_API_KEY=your-openai-api-key
LLM_MODEL=claude-3-5-sonnet-20241022
LLM_MAX_TOKENS=4000
LLM_TEMPERATURE=0.1
# Storage Configuration
STORAGE_TYPE=local
AWS_ACCESS_KEY_ID=your-aws-access-key
AWS_SECRET_ACCESS_KEY=your-aws-secret-key
AWS_REGION=us-east-1
AWS_S3_BUCKET=cim-processor-files
# JWT Configuration (for compatibility)
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
JWT_REFRESH_SECRET=your-super-secret-refresh-key-change-this-in-production
# Google Cloud Document AI Configuration
GCLOUD_PROJECT_ID=your-gcloud-project-id
DOCUMENT_AI_LOCATION=us
DOCUMENT_AI_PROCESSOR_ID=your-processor-id
GCS_BUCKET_NAME=your-gcs-bucket-name
DOCUMENT_AI_OUTPUT_BUCKET_NAME=your-document-ai-output-bucket
GOOGLE_APPLICATION_CREDENTIALS=./serviceAccountKey.json
# Processing Strategy
PROCESSING_STRATEGY=document_ai_genkit
# File Upload Configuration
MAX_FILE_SIZE=104857600
ALLOWED_FILE_TYPES=application/pdf
# Security Configuration
BCRYPT_ROUNDS=12
@@ -50,4 +46,30 @@ RATE_LIMIT_MAX_REQUESTS=100
# Logging Configuration
LOG_LEVEL=info
LOG_FILE=logs/app.log
LOG_FILE=logs/app.log
# Agentic RAG Configuration
AGENTIC_RAG_ENABLED=true
AGENTIC_RAG_MAX_AGENTS=6
AGENTIC_RAG_PARALLEL_PROCESSING=true
AGENTIC_RAG_VALIDATION_STRICT=true
AGENTIC_RAG_RETRY_ATTEMPTS=3
AGENTIC_RAG_TIMEOUT_PER_AGENT=60000
# Agent Configuration
AGENT_DOCUMENT_UNDERSTANDING_ENABLED=true
AGENT_FINANCIAL_ANALYSIS_ENABLED=true
AGENT_MARKET_ANALYSIS_ENABLED=true
AGENT_INVESTMENT_THESIS_ENABLED=true
AGENT_SYNTHESIS_ENABLED=true
AGENT_VALIDATION_ENABLED=true
# Quality Control
AGENTIC_RAG_QUALITY_THRESHOLD=0.8
AGENTIC_RAG_COMPLETENESS_THRESHOLD=0.9
AGENTIC_RAG_CONSISTENCY_CHECK=true
# Monitoring and Logging
AGENTIC_RAG_DETAILED_LOGGING=true
AGENTIC_RAG_PERFORMANCE_TRACKING=true
AGENTIC_RAG_ERROR_REPORTING=true