Skip to content

[BUG]: syncOfflineQueue silently skips ALL sessions when user is not authenticated β€” queued data orphaned foreverΒ #939

Description

@vipul674

πŸ“ Bug Description

The syncOfflineQueue function in src/services/syncQueue.ts silently skips every queued session when currentUserId is null (user not logged in), returning { synced: 0, failed: 0 } as if everything completed successfully. The caller assumes sync was successful with nothing to sync, but the queue still contains pending sessions that will never be delivered.

Bug location β€” src/services/syncQueue.ts:52-59:

export async function syncOfflineQueue(): Promise<SyncResult> {
  const currentUserId = getAuth().currentUser?.uid;  // null if not logged in
  const queue = getQueue();
  let synced = 0;
  let failed = 0;

  for (const session of queue) {
    if (!currentUserId || session.userId !== currentUserId) {
      continue;  // ← silently skips ALL sessions when currentUserId is null
    }
    // ... upload logic never reached ...
  }
  return { synced, failed };  // { synced: 0, failed: 0 }
}

When currentUserId is null:

  • First condition !currentUserId is true for EVERY session
  • Every session is skipped via continue
  • Function returns { synced: 0, failed: 0 } β€” caller assumes success
  • Queue data stays in localStorage forever

πŸ”„ Steps To Reproduce

  1. Record workout sessions while offline (or while not authenticated)
  2. Data gets pushed to the offline queue in localStorage
  3. User does NOT log in / auth session expires
  4. syncOfflineQueue() is called (e.g., via auto-sync timer)
  5. currentUserId is null
  6. All sessions skipped silently
  7. Returns { synced: 0, failed: 0 }
  8. Caller assumes nothing to sync β€” queue never retried or cleared
  9. Offline data lost permanently

βœ… Expected Behavior

  • When currentUserId is null, either:
    • Wait for authentication before attempting sync
    • Or return an error/status indicating auth is required
    • Or at minimum, log a warning that sessions are pending authentication

❌ Actual Behavior

  • Returns success with zero counts β€” indistinguishable from "nothing to sync"
  • Offline data permanently orphaned
  • No warning to user or developer

🌐 Browser

Chrome

πŸ’» Operating System

All

πŸ“¦ Node.js Version

v20.x

πŸ“Œ Additional Context

Impact: Offline workout data is silently lost when user is not authenticated during sync. User has no indication that data was not uploaded.
Level: 2 (Intermediate) β€” add auth-state check and appropriate handling

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions