GUEST SPACE ID FIX
Ecosistema completo para organización y gestión de contenido con interfaces espaciales
Guest Space ID Fix - Critical Bug
🎯 Status: ✅ FIXED
📋 Problem
Observed Issue:
- Guest users had URL with correct slug:
localhost:5200/temp-xxb7jayp/dashboard - But Space ID was MongoDB ObjectId:
6908faf777ab3ee134f76bc1 - Expected Space ID:
space_temp-xxb7jayp
Impact:
- Guest users couldn't properly persist data
- Space lookups failed (custom ID queries didn't work)
- All our backend fixes for guest users were ineffective
- Data would be lost on page refresh
🔍 Root Cause
In spaces.service.ts, the initializeUserSpace method had incorrect slug logic:
// ❌ BUG: This condition was FALSE for temp- slugs
const slug = spaceSlug && !spaceSlug.startsWith('temp-')
? spaceSlug
: this.generateSlug(defaultName); // Guest users fell through to this!
What Happened:
- Guest user arrives with
spaceSlug = 'temp-xxb7jayp' - Condition
!spaceSlug.startsWith('temp-')is FALSE - Falls through to
generateSlug(defaultName) - Creates space with generated slug instead of
temp-xxb7jayp createSpaceWithSlugnever receives the temp slug- Space gets created with MongoDB ObjectId instead of custom ID
✅ Solution
Updated the slug logic to explicitly handle guest users FIRST:
// ✅ FIX: Check for guest users explicitly
const slug = isGuestUser && spaceSlug
? spaceSlug // Keep temp-xxx for guest users
: spaceSlug && !spaceSlug.startsWith('temp-')
? spaceSlug // Use provided slug for authenticated users
: this.generateSlug(defaultName); // Generate from name
Flow After Fix:
- Guest user arrives with
userId = 'temp-xxb7jayp',spaceSlug = 'temp-xxb7jayp' isGuestUser = true(userId starts with 'temp-')slug = spaceSlug→'temp-xxb7jayp'✅createSpaceWithSlugreceives'temp-xxb7jayp'- Creates space with
_id: 'space_temp-xxb7jayp'✅
📊 Impact
| Before Fix | After Fix |
|---|---|
❌ Space ID: 6908faf777ab3ee134f76bc1 (ObjectId) |
✅ Space ID: space_temp-xxb7jayp (Custom) |
| ❌ Guest data not persisting | ✅ Guest data persists correctly |
| ❌ Backend lookups failing | ✅ Backend lookups work |
| ❌ Data lost on refresh | ✅ Data persists across refreshes |
🧪 Testing
To verify the fix:
Clear existing guest data (they have old ObjectId spaces):
# Use the nuclear reset button in the dashboard # OR manually clear IndexedDB + localStorageCreate new guest user:
- Open in incognito/private window
- Should get redirected to
/temp-xxxxxxxx/dashboard
Check Space ID in console:
debugUniverseStorage() // Look for "Current Space ID" // Should show: space_temp-xxxxxxxx ✅Create universe and refresh:
- Create a new universe
- Refresh the page
- Universe should still be there ✅
📝 Files Changed
apis/backend-api/src/app/spaces/spaces.service.ts
- Line 377-383: Updated slug generation logic in
initializeUserSpace()
🔗 Related Fixes
This completes the guest user persistence chain:
- ✅ Frontend allows guest users to call API (PERSISTENCE_BUG_FINAL_SOLUTION.md)
- ✅ Backend creates spaces with custom IDs (GUEST_SPACE_ID_FIX.md) ← This fix
- ✅ Backend handles custom ID lookups (already working)
- ✅ Guest-to-auth conversion ready (backend complete, frontend TODO)
⚠️ Important Notes
Existing Guest Users:
- Users who created spaces BEFORE this fix will have old ObjectId spaces
- They need to clear data and start fresh to get the new format
- The backend logs a warning for these users:
⚠️ GUEST USER has OLD SPACE FORMAT (ObjectId): 6908faf777ab3ee134f76bc1 ⚠️ Expected custom ID: space_temp-xxb7jayp ⚠️ To fix: User should clear data and create new space
Migration Path:
- Option 1: User clicks "Nuclear Reset" and starts fresh ✅
- Option 2: Build a migration tool (future enhancement)
- Option 3: User registers → space gets transferred with proper ID
Date Fixed: November 3, 2025
Fixed By: AI Assistant
Issue: Guest users getting MongoDB ObjectId instead of space_temp-xxx custom IDs