How do I correctly bundle a prepopulated Realm file into an app and then open and sync future changes for each distinct app user and/or device?
I am struggling to figure out how to prepopulate a synced realm. I’ve followed all of the suggestions I’ve seen online, but whenever I try to open the realm file with a sync configuration (full or query-based), I get the informative error message “Incompatible histories. Expected an empty Realm or a Realm written by Realm Mobile Platform.”
This will be a long post; I apologize. Some additional information, here is my tech stack:
React Native: 0.57.8
Steps I’ve followed up to this point:
- I developed the app with a single admin user; this admin has permissions to write data to the Realm Cloud instance and is also the sync user used during development
- I then integrated Auth0 and setup JWT authentication which I have verified is working and I see new Auth0 users in the Users table in my Realm Cloud instance
- Following advice I’ve found online, I made a copy of the Realm file to bundle with the app (1 opened the Realm file in a node process, 2 used
writeCopyToto generate a new file, 3 add that as an asset in XCode and use copyBundledRealmFiles during app startup)
- I can open the copied realm file in Realm studio without issue and I can open the Realm file in the app, without a sync configuration without issue which is what I do for new app users
When a new user registers:
- App starts and opens the bundled Realm file without sync
- User initiates signup and is directed to the Auth0 registration page
- If successful, Auth0 returns the access, refresh and JWT tokens
- Create a sync user using the Auth0 JWT
- If successful, do a
writeCopyToof the initially opened Realm file, create a sync configuration for the newly created (using
user.createConfiguration) and specifying the path as the newly copied realm file
- Receive the histories error
I have exhausted my research into the histories error and how to bundle a prepopulated realm file. I have put a lot of time and investment into Realm, but if I can’t solve this seemingly simple problem I’m not sure I can continue using it.
The only solution that I have found to work is what I started with during development: use a single admin user across all app sessions and devices which does not seem viable in a production release.