Reputation: 1197
My goal is pretty simple: I need to create private RealmObjects
in a shared Realm
.
I already created objects and stored them in a shared realm
. I would like to give users the ability to store their objects privately though. As far as I know I have two ways to accomplish this, but none of them is working.
SOLUTION 1: using permissions to let Users
share Realm objects to each other like in the following sample:
public static void setActiveUser(final SyncUser user) {
if (user.isValid()) {
SyncConfiguration defaultConfig = new SyncConfiguration.Builder(user, Colombo.SERVER_URL).build();
Realm.setDefaultConfiguration(defaultConfig);
Realm realm = user.getManagementRealm();
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
String includeAll = "*";
change = new PermissionChange(includeAll, includeAll, true, true, false);
realm.insert(change);
}
});
}
}
Unfortunately this doesn't work, the synchronized Realms
are visibile just to the current SyncUser
.
SOLUTION 2: Create a "common" SyncUser
to save/show public items and a private SyncUser
for each registered user to collect his private items, switching from common to private SyncUser
depending on the needs. Anyway it seems quite inefficient to me. How does it sound to you? Do you think there's another way I can do it?
Upvotes: 0
Views: 190
Reputation: 6715
You cannot use Realm's authentication mechanism to provide different login permissions to different accounts for a single Realm.
As Nabil said, you can programmatically control access by assigning UUIDs to users, and then querying only for them per user.
Upvotes: 1