User data storage

I’m looking for some guidance on storing user data. I’ve made a couple of maybe odd/uncommon choices here and now I’m a little stuck.

Currently, upon signup, a user record is created on Atlas via a node API.
Then, when a user verifies their email, a parameter on that record (‘verified’) is set to true, again through the API.
Then, on login, a token is created via node API and then used to login to Realm, which creates a Realm user.

So now I have a user record on Atlas with one id and a realm user with a different id which is not ideal and creates confusion. Should I be trying to set the id on the record to match the realm user after it is created? Or can/should I create the realm user with the same id as the record?

So the solution I ended on here is to link the realm user with the user record on MongoDB using ‘custom user data’.

I added a key to the users record ‘realmUser’ and adjusted my Node API to set this after a user has logged in to Realm. This is a little annoying because it adds an extra API call to the login process. But it works for now.

Then I enabled Custom User Data. It can be kinda tough to find this view. It’s a header on the App Users view under Realm. You just set the name of the field on your MongoDB user record that you’re using to store the id of your realm user.

So now I can pull custom data directly from the realm user wherever it is used.

const realmApp = new Realm.App({ id: REALM_APP_ID });
const user = realmApp.currentUser

One you have a user, you can get the custom data with:
user.customData

Keep in mind that this data is only refreshed on Realm login. So if you’re not seeing some of your changes to this data, you may need to manually call.
user.refreshCustomData();
to get them to pop up. Or just logout and log back in.

I still have some confusion about how best to use this system, particularly when it comes to storing/editing passwords, but I think I answered the bulk of my question.