🔍 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:
parent
dc867f2a2b
commit
111658436f
1 changed files with 25 additions and 6 deletions
|
|
@ -40,33 +40,52 @@ export default function Collections() {
|
|||
}
|
||||
}, [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 () => {
|
||||
try {
|
||||
const response = await fetch('/api/collections');
|
||||
|
||||
if (response.ok) {
|
||||
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(
|
||||
data.map(async (collection) => {
|
||||
try {
|
||||
const identifier = collection.slug || collection.id;
|
||||
const thumbnailResponse = await fetch(`/api/collections/${identifier}/thumbnails`);
|
||||
const thumbnails = thumbnailResponse.ok ? await thumbnailResponse.json() : [];
|
||||
return { ...collection, thumbnails };
|
||||
if (thumbnailResponse.ok) {
|
||||
const thumbnailData = await thumbnailResponse.json();
|
||||
return { ...collection, thumbnails: thumbnailData.thumbnails };
|
||||
}
|
||||
return { ...collection, thumbnails: [] };
|
||||
} 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: [] };
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
setCollections(collectionsWithThumbnails);
|
||||
} else {
|
||||
console.error('Failed to fetch collections');
|
||||
setCollections([]); // Empty array on error
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching collections:', error);
|
||||
setCollections([]); // Empty array on error
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue