Commit graph

33 commits

Author SHA1 Message Date
Randall Stillwell
7057417a89 Implement database-based card loading system - add card loader API, database search, and admin interface 2025-07-23 06:50:44 -05:00
Randall Stillwell
dbb0353def Fix Lorcana API search syntax - use correct endpoints and search parameters 2025-07-23 06:34:21 -05:00
Randall Stillwell
0a09b333c4 Fix Lorcana API endpoints based on official documentation - update to correct API URLs 2025-07-23 06:28:22 -05:00
Randall Stillwell
5aa168bd24 Add CORS proxy for Lorcana APIs and improve error handling - fix CORS issues and 500 errors 2025-07-23 06:13:49 -05:00
Randall Stillwell
d27a04e460 Fix Lorcana API integration and user-cards 500 error - add dual API support and database table checks 2025-07-22 21:54:42 -05:00
Randall Stillwell
40928bbbda Add user cards API endpoints - fix Cards page error by implementing missing /api/user-cards endpoints 2025-07-22 21:43:53 -05:00
Randall Stillwell
bf569360cf Add auto-migration for OCR settings column
🔄 Database Auto-Migration:
- Add automatic schema update in user preferences API
- Ensures ocr_settings column exists when first accessed
- Uses ADD COLUMN IF NOT EXISTS for safe migration
- Handles case where column might already exist
- No need for separate migration endpoint

This ensures the settings page will work immediately after deployment
without requiring manual database updates.
2025-07-22 10:57:20 -05:00
Randall Stillwell
f441d1aee5 Fix Vercel function limit and eslint warnings
🔧 Vercel Function Limit Fix:
- Remove unnecessary API functions to get under 12 function limit
- Delete api/simple.js (test function)
- Delete api/migrate.ts (old migration)
- Delete api/admin/promote-user.js (one-time function)
- Delete api/admin/update-preferences-schema.js (migration)
- Delete api/v1/ directory (old API versions)
- Now at 8 functions (well under 12 limit)

🚨 ESLint Warning Fixes:
- Fix unnecessary escape characters in regex patterns
- Replace [:\-] with [:−] in aiOcr.ts regex patterns

 Build should now succeed on Vercel Hobby plan
2025-07-22 10:56:54 -05:00
Randall Stillwell
7463551065 Move OCR settings to comprehensive user settings system
🏗️ User Settings System:
- Create comprehensive Settings page with tabbed interface
- Move OCR configuration from modal to dedicated settings tab
- Add API endpoints for user preferences (GET/PUT)
- Store settings in database user_preferences table with ocr_settings column
- Add Settings link to navbar user dropdown

⚙️ Settings Features:
- General tab: default view, items per page, theme, animations
- AI OCR tab: service selection, API keys, confidence threshold
- Privacy tab: public collections/decks defaults
- Real-time API key testing for OpenAI and Ollama
- Persistent storage in database instead of localStorage

🔄 Integration:
- Remove old OCRSettings modal from Scanner page
- Add Settings route to App.tsx routing
- Update navbar with Settings link in user dropdown
- Prepare for AI OCR service to read from user preferences

Next: Update AI OCR service to use saved user preferences instead of localStorage
2025-07-22 10:53:44 -05:00
Randall Stillwell
7dc8718512 Fix build issues and update dependencies
🔧 Build Fixes:
- Update Node.js version from 18.x to 22.x (required by Vercel)
- Remove debug endpoints to get under 12 function limit for Hobby plan
- Downgrade React from 19.x to 18.x for better compatibility
- Update react-router-dom to v6.28.0 (compatible with Node 22)
- Update TypeScript to v5.7.3
- Update React types to match React version

Functions count: 12/12 (at limit for Hobby plan)

Core API endpoints:
 auth/login.js, auth/register.js
 collections/index.js, collections/add-card.js
 cards/find-or-create.js
 admin/users.js, admin/promote-user.js
 setup-auth.js, simple.js
 Legacy: migrate.ts, v1/cards/[id].ts, v1/cards/index.ts
2025-07-22 08:18:51 -05:00
Randall Stillwell
d71d85ee43 Add database test endpoint for local debugging
🔧 Local Development Debugging:
- Add api/test-db-local.js for database connection testing
- Helps diagnose local environment issues
- Tests table existence and user data

Note: Local Vercel dev having database connection issues
Consider testing on production environment instead
2025-07-22 08:13:20 -05:00
Randall Stillwell
e9b2da09a5 Implement complete card scanning and collection flow - ready for local testing 2025-07-22 08:01:20 -05:00
Randall Stillwell
08e2664a9a Fix admin users API endpoint
🔧 Convert TypeScript to JavaScript:
- Replace api/admin/users.ts with api/admin/users.js
- Use req, res pattern instead of NextRequest/NextResponse
- Fix req.headers.get() -> req.headers.authorization
- Use url.parse() for query parameters
- Support GET (list users), PUT (update), DELETE (deactivate)
- Proper admin authentication and error handling

Resolves: req.headers.get is not a function error
2025-07-22 07:36:37 -05:00
Randall Stillwell
04d7383025 Add admin promotion options 2025-07-22 07:23:03 -05:00
Randall Stillwell
824c962f47 Add simple test user promotion endpoint
🔧 Simple Admin Promotion:
- Create api/promote-testuser.js endpoint
- Promotes user ID 1 (testuser) to admin role
- No authentication required (for initial setup)
- Uses working JavaScript + req/res pattern
- Simpler than complex promote-user endpoint
2025-07-22 07:11:02 -05:00
Randall Stillwell
5dd7de86ad Add debug logging to promote-user endpoint
🐛 Debug:
- Log request body type and content
- Identify why JSON parsing is failing
- Temporary debug version to diagnose issue
2025-07-22 07:10:14 -05:00
Randall Stillwell
028c5396f3 Fix promote-user endpoint request body parsing
🔧 Fix:
- Use req.body directly instead of req.text() + JSON.parse()
- Match pattern used in working auth endpoints
- Should resolve NOT_FOUND and parsing issues
2025-07-22 07:09:14 -05:00
Randall Stillwell
f7735ba8d9 Add user promotion endpoint
🔧 Admin Management:
- Add api/admin/promote-user.js endpoint
- Allows promoting users to admin role by username or userId
- Checks for existing admin status
- Returns updated user info with roles
- Handles database errors gracefully

Usage: POST /api/admin/promote-user with { username: 'testuser' }
2025-07-22 07:08:09 -05:00
Randall Stillwell
299fb1916b Remove conflicting TypeScript API files
🔧 Build Fix:
- Remove .ts versions of API files that conflict with .js versions
- Keep only working JavaScript API endpoints:
  - api/auth/login.js
  - api/auth/register.js
  - api/setup-auth.js
  - api/simple.js
  - api/debug.js

This resolves the Vercel build error about conflicting file paths.
2025-07-22 06:55:09 -05:00
Randall Stillwell
653e35baee Add comprehensive debug endpoint to check environment variables
�� Debug Information:
- New /api/debug endpoint with detailed environment info
- Check for DATABASE_URL and JWT_SECRET presence
- Show environment variable keys related to database
- Force fresh deployment with new endpoint name

This will help identify if environment variables are properly configured in Vercel.
2025-07-22 06:53:36 -05:00
Randall Stillwell
a8abe0130f Add environment variable debugging to simple endpoint 2025-07-22 06:52:30 -05:00
Randall Stillwell
45bca2873f Convert auth endpoints to working Vercel function format
🔧 API Format Fix:
- Convert register.ts to register.js using req/res pattern
- Convert login.ts to login.js using req/res pattern
- Convert setup-auth.ts to setup-auth.js using req/res pattern
- Use CommonJS require() instead of ES6 imports
- Use traditional Vercel function signature that works

 Working Format:
- export default async function handler(req, res)
- req.body for request data (auto-parsed by Vercel)
- res.status().json() for responses
- CommonJS modules with require()

This should resolve all timeout issues and make authentication work properly.
2025-07-22 06:46:09 -05:00
Randall Stillwell
b462010434 Add proper Next.js API routes and install Next.js types
🔧 API Route Format:
- Add /api/simple.js using standard Vercel function format
- Add /api/hello.ts using proper Next.js API route format
- Install Next.js and types for proper API route support

🧪 Testing Multiple Formats:
- JavaScript endpoint: /api/simple.js
- TypeScript endpoint: /api/hello.ts
- Both use traditional req/res pattern instead of NextRequest/NextResponse

This should help identify the correct API format for Vercel functions.
2025-07-22 06:43:39 -05:00
Randall Stillwell
b7c6e674a6 Simplify Vercel configuration and add basic test endpoint
🔧 Configuration Changes:
- Remove specific runtime version from vercel.json
- Remove buildCommand that might be causing conflicts
- Let Vercel use default Node.js runtime settings

🧪 Simple Test Endpoint:
- Add /api/simple with minimal dependencies
- Use traditional Vercel function signature (req, res)
- No imports or complex operations to isolate the issue

This should help identify if the problem is with our function configuration, imports, or Vercel setup.
2025-07-22 06:42:19 -05:00
Randall Stillwell
323d6a3dd3 Add health check and improve database test endpoint
🔧 Improvements:
- Add /api/health endpoint for basic API functionality testing
- Improve /api/test-db with timeout handling and better error reporting
- Add environment variable checks before database operations
- Add connection timeouts to prevent function timeouts
- Better error handling and logging

🧪 Testing Endpoints:
- /api/health - Simple API health check (no DB required)
- /api/test-db - Database connectivity test with timeout protection

These changes should help identify whether the issue is with API routing, environment variables, or database connectivity.
2025-07-22 06:36:13 -05:00
Randall Stillwell
0531f25cbb Add debugging tools and optimize auth endpoints
🔧 Debugging Improvements:
- Optimize setup-auth endpoint to avoid timeouts
- Add table existence checks before operations
- Simplify permission system for faster setup
- Add environment variable validation
- Create test-db endpoint for connection debugging

🚀 Performance Optimizations:
- Break down large SQL queries into smaller chunks
- Add early returns for already-setup scenarios
- Reduce permission complexity during initial setup
- Better error messages for troubleshooting

🧪 New Debug Endpoints:
- /api/test-db - Test database connectivity
- /api/setup-auth - Optimized schema setup

These changes should resolve timeout issues and provide better debugging information for authentication problems.
2025-07-21 21:39:08 -05:00
Randall Stillwell
07b3dda6fa Fix Vercel function request body parsing
🐛 Bug Fix:
- Replace req.json() with req.text() + JSON.parse() for Vercel compatibility
- Add proper error handling for malformed JSON requests
- Fix authentication endpoints (login/register) body parsing
- Fix admin users endpoint body parsing

🔧 Technical Details:
- Vercel functions don't support req.json() method directly
- Use req.text() to get raw body content then parse manually
- Add try/catch blocks for JSON parsing errors
- Maintain same API interface and error responses

 Endpoints Fixed:
- /api/auth/register - User registration
- /api/auth/login - User authentication
- /api/admin/users - Admin user management

This resolves the 'req.json is not a function' error in production.
2025-07-21 21:11:13 -05:00
Randall Stillwell
dc95d0d76d Implement complete user authentication and admin panel system
 Features Added:
- User registration and login with JWT authentication
- Role-based access control (user/admin)
- Comprehensive admin panel with user management
- Password hashing with bcrypt
- Session management and token storage
- Protected routes and public routes
- Modern login/register forms with validation

🗄️ Database Schema:
- Users table with profile information
- Roles and permissions system
- User-role junction tables
- Session management tables
- Database triggers and indexes

🎨 UI/UX Improvements:
- Updated navigation with user menu
- Admin badge and access controls
- Responsive authentication forms
- Loading states and error handling
- Role-based UI elements

🔧 API Endpoints:
- /api/auth/login - User authentication
- /api/auth/register - User registration
- /api/admin/users - User management (admin only)
- /api/setup-auth - Database schema setup

🚀 Admin Panel Features:
- User listing with search and pagination
- Role assignment (user/admin)
- User activation/deactivation
- System dashboard with stats
- Card management placeholder
- Real-time user management
2025-07-21 21:06:38 -05:00
Randall Stillwell
9243f6ff4e Fix Vercel ES module import issues
- Change JSON import to use require() to avoid module loading issues
- Add api/tsconfig.json with CommonJS module configuration
- Update Vercel Node.js runtime to @vercel/node@3.2.0
- Add buildCommand to vercel.json for proper compilation
- Fix 'Cannot use import statement outside a module' error
2025-07-21 16:12:24 -05:00
Randall Stillwell
6f40a5058d Fix Node.js 18 compatibility for Vercel deployment
- Switch from @neondatabase/serverless to standard 'pg' client for Node.js 18 support
- Update Node.js version to 18.x as required by Vercel
- Replace Neon template literals with standard parameterized queries
- Add proper connection pooling and SSL configuration for production
- All API endpoints updated: /api/v1/cards/, /api/v1/cards/[id], /api/migrate
- Build tested and working successfully
2025-07-21 16:08:45 -05:00
Randall Stillwell
33345a9f51 Fix Vercel deployment issues
- Update Node.js version from 18.x to 22.x for Neon compatibility
- Fix TypeScript errors by properly typing error objects as Error
- Resolve engine compatibility issues with @neondatabase/serverless and react-router
- Add proper error type casting in all API endpoints
- Fix FUNCTION_INVOCATION_FAILED crashes
2025-07-21 15:56:26 -05:00
Randall Stillwell
4821d1a389 Switch from JSON to Neon database for card data
- Add /api/migrate endpoint to populate Neon database with existing JSON data
- Update /api/v1/cards/ to query Neon database instead of JSON file
- Update /api/v1/cards/[id] to fetch single cards from Neon
- Add proper error handling and development debugging
- Maintain backward compatibility with existing API interface
- Ready to migrate card data to PostgreSQL
2025-07-21 15:46:58 -05:00
Randall Stillwell
6b81ed38b0 🚀 TCG Vault - Complete All-Vercel Setup
 Features:
- Camera OCR card scanning with Tesseract.js
- Beautiful glowing card effects and animations
- Intelligent card matching and recognition
- Mobile-responsive design with Tailwind CSS

🏗️ Architecture:
- Frontend: React TypeScript application
- Backend: Vercel Functions (replacing FastAPI)
- Database: JSON file with exported card data
- Deployment: Single Vercel project

📁 Structure:
- api/ - Vercel Functions backend endpoints
- src/ - React frontend components and logic
- src/data/cards.json - Card database (12 cards)
- vercel.json - Optimized Vercel configuration

💰 Cost: /bin/zsh additional (uses existing Vercel Pro)
🚀 Ready for immediate Vercel deployment
2025-07-21 13:53:06 -05:00