Keeping the token fresh
Access tokens last one hour, so refresh is not optional — a client that only stores the access token stops working mid-session. Refresh tokens last a year but rotate on every use: each refresh returns a new one and immediately invalidates the old. That rotation is the part worth care on Android. Several coroutines hitting the API at once will each see401 and each try to refresh, and those refreshes
invalidate one another — signing the user out. Serialise them behind a mutex so
only the first refreshes and the rest await its result:
401 exactly once. If the replay also fails, the refresh token is gone
and the profile must run device authorization again.
Recommended initial-sync ordering:
applyChangeOrTombstone should key on resource plus resourceId rather than
assume each change arrives once.
Use one encrypted token record and one sync cursor per Nuvio profile. Never
share an access token or cached mirror between profiles.