Starting out with Anonymous auth before Authenticating

In my old legacy realm cloud application, I was using a method where I would have a local realm when a user first starting using the app.

Eventually, if they decide to start paying for sync, I would migrate that realm to a synced realm.

I’m working on migrating my app to MongoDB Realm from Realm Cloud currently (this is a react-native app).

My thought is that instead of doing this difficult client side migration when a user toggles sync on/off, that I could just start off with an anonymous user so that there is only ever one schema / one type of Realm.

Then, if they pay for syncing later, I can create a JWT login to gate access to authenticate the user and then use that on new devices to link to the same data set.

@Kenneth_Geisshirt mentioned that it is possible to link credentials in v10+ at the end of this github issue: Convert Realm Cloud Anonymous User into an authenticated User · Issue #2211 · realm/realm-js · GitHub

I’m just wondering if there is any example of how to do this? Does creating a login automatically use the previous anonymous user’s realm user? Are there any drawbacks? I also read somewhere that the anonymous user isn’t permanent and data may be lost, which is obviously not usable in production.

Would love to hear how anyone else is solving this issue.

Thanks.

–Kurt

Hi @Kurt_Libby1, I’ve not tried it myself but the React Native SDK does include a feature to link identities: https://docs.mongodb.com/realm/sdk/react-native/advanced/link-identities/

Thank you!

That was exactly what I was looking for. Working on it now.

Wondering this still though:

Are there any drawbacks? I also read somewhere that the anonymous user isn’t permanent and data may be lost, which is obviously not usable in production.

Is there any case that would cause the anonymous user to lose their data prior to linking to an auth service?

–Kurt