π 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
- Record workout sessions while offline (or while not authenticated)
- Data gets pushed to the offline queue in localStorage
- User does NOT log in / auth session expires
syncOfflineQueue() is called (e.g., via auto-sync timer)
currentUserId is null
- All sessions skipped silently
- Returns
{ synced: 0, failed: 0 }
- Caller assumes nothing to sync β queue never retried or cleared
- 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
π Bug Description
The
syncOfflineQueuefunction insrc/services/syncQueue.tssilently skips every queued session whencurrentUserIdisnull(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:When
currentUserIdis null:!currentUserIdistruefor EVERY sessioncontinue{ synced: 0, failed: 0 }β caller assumes successπ Steps To Reproduce
syncOfflineQueue()is called (e.g., via auto-sync timer)currentUserIdisnull{ synced: 0, failed: 0 }β Expected Behavior
currentUserIdis null, either:β Actual Behavior
π 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