Switching from local realm to a synced realm on login

This is a follow-up to this github thread: https://github.com/realm/realm-js/issues/4659

Long story short, we have an app where user can create data before they’ve actually signed in to their account. On signing in, this locally created data has to sync with the server, unless the user has specified that they don’t want the data to sync. In that case, the data should be stored locally, until said otherwise.

In Github, a solution was offered for switching out the realms with writeCopyTo and conditional config for RealmProvider. Unfortunately, I am running into problems with setting up a subscription. This is the error that I’m getting on logging in and switching realms:

Error:

Client attempted a write that is outside of permissions or query filters; it has been reverted (ProtocolErrorCode=231)
Details:
{
  "Contact": {
    "0.8426483083351229_synced": "cannot write to table \"Contact\" before opening a subscription on it"
  }
}
Function Call Location:
IE
Remote IP Address:
213.35.181.75
SDK:
ios vRealmJS/10.19.1
Platform Version:
15.4

It seems that the subscription doesn’t exist at the time and so the write gets reverted. Can you help us by pointing out a way to get past this?

Also, is there any way to achieve what we’re trying to achieve - partially syncing data from realm to cloud? While the user has turned off data syncing, we still want to sync some information about the account.

My code demo: https://github.com/soliloquyx/realm-sync-demo-1

Unfortunately it is currently not possible to convert a local Realm to a Flexible Sync Realm (see the Note in our documentation). You will have to copy the objects manually - or always start with a Flexible Sync Realm.

Thanks for the quick reply!

What about syncing data partially, based on users selection to turn off cloud syncing in our app? Can this be achieved with flexible sync permissions/rules or do we need to have 2 realm instances (local/synced) in use?