I finally fixed the sync issue. It was a weird permission configuration mistake I made yesterday.
I was getting the following error while syncing my data with Atlas Device Sync Cloud from the local Realm using the RealmSDK:
Client attempted a write that is outside of permissions or query filters: write to in table expense not allowed Logs:
Because I had the following permission rules setup:
{
"read": {
"author": "%%user.id"
},
"write": {
"author": "%%user.id"
}
}
After some intensive debugging, I realized that the type of userId provided by Atlas App Services Authentication is of type string, but the one we store in the author field is of type ObjectId, therefore I updated my permission expression as below:
{
"read": {
"author": { "%stringToOid": "%%user.id" }
},
"write": {
"author": { "%stringToOid": "%%user.id" }
}
}
And voila, it started working. So with this very small configuration change I migrated my app from Partition based to Flexible Sync:
<RealmProvider
sync={{
user,
flexible: true,
initialSubscriptions: {
update: (subs, realm) => {
subs.add(realm.objects('expense'));
},
rerunOnOpen: true,
},
error: handleSyncError,
}}>
{children}
</RealmProvider>