Synchronizing multiple users to same DB

I have a situation where I want to allow two users to sign in to the same device and have their data synchronized to the device. The two users have different lists of channels they can access. Some channels are shared and some are not (e.g. one user is a worker and the other is a supervisor).

I actually want to share documents between the users, because the supervisor should be able to view and edit the worker’s data, potentially while offline, so I’m having both users replicate to the same database on the device.

What I’m finding is that if the worker user replicates first, all of its data will be downloaded. If I then attempt to replicate with the supervisor user, CB Lite acts as if there’s nothing to new to pull and gives up. So the supervisor can see the worker’s documents, but does not receive any of the supervisor specific documents.

Is this the expected behavior, and is there a workaround other than creating local databases on a per-user basis?

1 Like

It’s generally a bad idea to share multiple users’ data in one database. Couchbase Lite has no access permissions, so all users’ documents will be accessible in the local database. You can work around that by checking permissions yourself, but that gets awkward with things like view queries, which would have different results depending on which user is active.

If you need the supervisor to be able to access the worker’s data, just let the app open the worker’s database as well while the supervisor is logged in.

What I’m finding is that if the worker user replicates first, all of its data will be downloaded. If I then attempt to replicate with the supervisor user, CB Lite acts as if there’s nothing to new to pull and gives up.

Replications authenticated as different users don’t store independent checkpoints, so that explains the behavior you’re seeing.