🔧 Fix 'All My Cards' Collection Access Issue

🐛 Root Cause:
- Collection detail page was not sending auth token in API requests
- This caused the API to fallback to admin user authentication
- Bob's 'All My Cards' collection was inaccessible to admin user

 Solution:
- Added Authorization header to fetchCollectionData() function
- Added Authorization header to collection cards fetch request
- Both requests now properly authenticate as the logged-in user

🔍 Debug Results:
- Token verification was working correctly for other API calls
- Only the main collection fetch was missing authentication
- This explains the 404 error for system collections

The 'All My Cards' collection should now be accessible! 🚀
This commit is contained in:
Randall Stillwell 2025-07-27 21:30:32 -05:00
parent 85131240e5
commit eeee1c1f6b
2 changed files with 10 additions and 5 deletions

View file

@ -13,14 +13,11 @@ export async function getUserFromRequest(req) {
if (!authHeader || !authHeader.startsWith('Bearer ')) {
// For development, return user ID 1 if no token (should be removed in production)
console.warn('⚠️ Development mode: Using fallback user authentication');
console.warn('⚠️ No auth header found:', authHeader);
return { userId: 1, email: 'admin@tcgvault.com', role: 'admin' };
}
const token = authHeader.substring(7);
console.log('🔍 Attempting to verify token:', token.substring(0, 20) + '...');
const decoded = jwt.verify(token, JWT_SECRET);
console.log('✅ Token decoded successfully:', decoded);
// Get user data from database
const result = await sql`

View file

@ -64,7 +64,11 @@ export default function CollectionView() {
const fetchCollectionData = async () => {
try {
const response = await fetch(`/api/collections/${identifier}`);
const response = await fetch(`/api/collections/${identifier}`, {
headers: {
'Authorization': `Bearer ${localStorage.getItem('auth_token')}`
}
});
if (response.ok) {
const data = await response.json();
@ -85,7 +89,11 @@ export default function CollectionView() {
});
// Fetch collection cards
const cardsResponse = await fetch(`/api/collections/${identifier}/cards`);
const cardsResponse = await fetch(`/api/collections/${identifier}/cards`, {
headers: {
'Authorization': `Bearer ${localStorage.getItem('auth_token')}`
}
});
if (cardsResponse.ok) {
const cardsData = await cardsResponse.json();
setCards(cardsData.cards || []);