diff --git a/pages/api/collections/[identifier]/thumbnails.js b/pages/api/collections/[identifier]/thumbnails.js index a6d08f9..163ab8e 100644 --- a/pages/api/collections/[identifier]/thumbnails.js +++ b/pages/api/collections/[identifier]/thumbnails.js @@ -34,9 +34,12 @@ export default async function handler(req, res) { // Determine if identifier is a slug or numeric ID const isSlug = isValidSlug(identifier) || isNaN(parseInt(identifier)); + console.log('🔍 Identifier analysis:', { identifier, isSlug, isValidSlug: isValidSlug(identifier), isNaN: isNaN(parseInt(identifier)) }); + // Verify user has access to this collection let collectionResult; if (isSlug) { + console.log('🔍 Querying by slug:', identifier); collectionResult = await sql` SELECT c.*, cp.role as user_role FROM collections c @@ -50,6 +53,7 @@ export default async function handler(req, res) { `; } else { const numericId = parseInt(identifier); + console.log('🔍 Querying by ID:', numericId); collectionResult = await sql` SELECT c.*, cp.role as user_role FROM collections c @@ -67,7 +71,20 @@ export default async function handler(req, res) { return res.status(404).json({ error: 'Collection not found or access denied' }); } + console.log('🔍 Collection result:', { + identifier, + isSlug, + resultLength: collectionResult.length, + collection: collectionResult[0] + }); + const collection = collectionResult[0]; + + // Add debugging and validation + if (!collection || !collection.id) { + console.error('Collection data invalid:', { collection, identifier, isSlug }); + return res.status(500).json({ error: 'Collection data invalid' }); + } // Get the top 5 rarest cards from the collection const thumbnailsResult = await sql`