🔍 Add Debug Logging for Collection Ownership Issue

Added debug logging to investigate why ownership indicators aren't showing:
- Log current user in collections page
- Log collections data with userRole and creator info
- Log API response data to see what backend returns
- Enhanced error handling in fetchCollections

This will help identify if the issue is:
- Frontend auth context not working properly
- API not returning correct userRole values
- Collections state not updating correctly
- Permission indicator not receiving proper props

Debug logs will show in browser console when testing Bob's login.
This commit is contained in:
Randall Stillwell 2025-07-27 12:34:41 -05:00
parent dc867f2a2b
commit 111658436f

View file

@ -40,33 +40,52 @@ export default function Collections() {
} }
}, [user]); }, [user]);
// Debug logging
useEffect(() => {
console.log('🔍 Debug - Current user:', user);
console.log('🔍 Debug - Collections:', collections.map(c => ({
name: c.name,
userRole: c.userRole,
creator: c.creator
})));
}, [user, collections]);
const fetchCollections = async () => { const fetchCollections = async () => {
try { try {
const response = await fetch('/api/collections'); const response = await fetch('/api/collections');
if (response.ok) { if (response.ok) {
const data = await response.json(); const data = await response.json();
// Fetch thumbnail cards for each collection console.log('🔍 Debug - API response:', data.map(c => ({
name: c.name,
userRole: c.userRole,
creator: c.creator
})));
// Fetch thumbnails for each collection
const collectionsWithThumbnails = await Promise.all( const collectionsWithThumbnails = await Promise.all(
data.map(async (collection) => { data.map(async (collection) => {
try { try {
const identifier = collection.slug || collection.id; const identifier = collection.slug || collection.id;
const thumbnailResponse = await fetch(`/api/collections/${identifier}/thumbnails`); const thumbnailResponse = await fetch(`/api/collections/${identifier}/thumbnails`);
const thumbnails = thumbnailResponse.ok ? await thumbnailResponse.json() : []; if (thumbnailResponse.ok) {
return { ...collection, thumbnails }; const thumbnailData = await thumbnailResponse.json();
return { ...collection, thumbnails: thumbnailData.thumbnails };
}
return { ...collection, thumbnails: [] };
} catch (error) { } catch (error) {
console.error(`Error fetching thumbnails for collection ${collection.slug || collection.id}:`, error); console.error(`Error fetching thumbnails for collection ${collection.id}:`, error);
return { ...collection, thumbnails: [] }; return { ...collection, thumbnails: [] };
} }
}) })
); );
setCollections(collectionsWithThumbnails); setCollections(collectionsWithThumbnails);
} else { } else {
console.error('Failed to fetch collections'); console.error('Failed to fetch collections');
setCollections([]); // Empty array on error
} }
} catch (error) { } catch (error) {
console.error('Error fetching collections:', error); console.error('Error fetching collections:', error);
setCollections([]); // Empty array on error
} finally { } finally {
setLoading(false); setLoading(false);
} }