I am currently building a multi-stage environment with multiple Realm apps, but I would like to share the App users between multiple apps. As they are managed by Realm internally, I am wondering if there is any way to achieve the following:
I already created two databases: “db_prod” and "db_develop
I already created three realm apps: “app_prod”, “app_staging”, “app_develop”
The Realm app “app_develop” is used only for development, which can lead to bigger changes without prior migration etc… It should also have it’s own list of App Users, and i t works with the database “db_develop”. It is isolated from the rest to not interfere with the production data (maybe even own cluster at some point, but for now only different database).
The “app_staging” is the staging/QA app. It is used to test new features/setups using the production data, before the frontend clients are public. In our case we are building iOS apps and I want to ship them to Testflight for beta testing the staging environment. This app has the same schemas, functions etc. as “app_develop” but it uses the “db_prod” database. Ideally this app does not manage its own list of users, instead it uses the same App Users as the “app_prod”, so I can communicate via both apps, without changing the account. I want my beta testers to sign up in the staging environment and when we ship the new release, they should be able to seamlessly upgrade to the latest release.
The “app_prod” is the production app. It uses the database “db_prod” and manages all the production users/data etc. It’s basically the same setup as “app_develop” but long-term stability.
I have set up the authentication providers Apple, Google and Email.
All my users have associated user data which works good with a customer trigger function.
The staging and the production Realm App are both able to access the user data records from the “db_prod” but I am facing the issue, that the two App Users lists are not synchronized.
As an example I created an email-password user with the same email in the production and the staging Realm app and it created two different id’s:
- app_prod: 61a9d16bf69dc6c736490b13
- app_staging: 61a9d1ae7e4d4f9cf8f1a405
I have set up my custom user data, to associate the App Users id with the field
userId in my user data records. I also changed the realm apps to use a separate “db_auth” database, which handles shared user entities. Still I am stuck with two records with different id’s.
Now I could go ahead and change the field
userId to be two id’s, basically
userId_staging, but that would still create two user records I have to merge manually.
I believe that I can’t rely on user metadata such as the email to find existing user records, as these might be randomly generated (Apple’s hidden email feature) or not even existing (not providing the email OAuth scope).
I have already set up a full multi-stage CI/CD which manages the individual Realm Apps. I got the idea from this MongoDB article: How to Build CI/CD Pipelines for MongoDB Realm Apps Using GitHub Actions | MongoDB
- Is it possible to achieve what I want here?
- Is there a best-practice guide how to allow multiple Realm Apps use the same user base?
- Is there a best-practice guide for setting up multi-stage/multi-tenancy Realm apps with user accounts?
- Do I need to use an external auth provider, so my two Realm Apps can use the same login accounts?