Accessing authentication provider meta data from a Swift client

We are writing a Swift client that uses as custom JWT authentication provider. I have set up the meta data fields and they are showing up in the JWT token. And the data is showing up in the Provider Data for each user in the Users table. My only question is this. How do I access this provider data from a Swift client using the MongoDB Realm SDK? We have no problem accessing this data on the Javascript backend functions.


Hi @Richard_Krueger, I have the same problem now. After I can successfully store the date, my RealmSwift SDK is returning nil for the SyncUsers “customData” property, even after refreshing it with no error. Please let me know in case you found a solution for this. I ´m investigating it currently.

@Christian_Huck so custom data is not the same thing as provider metadata. The first is set up the through a custom data collection as described here

The second is meta data that is passed through the JWT token itself as described here

So custom data (as opposed to meta-data) is a collection where your backend server puts data that relates to each user. The custom data collection must be setup by the developer before the user logs in. Your custom data is probably nil because you have not set it up. Also, the RLMSyncUser has a method called refreshCustomData that you can call after you log in. For the moment, I have not seen any way to access the user’s provider data directly from within the client code. This is odd, because you can get access to it from Javascript in a backend trigger function. I have an outstanding ticket on this forum, but I have not heard back from the MongoDB Realm team on this. Perhaps the best practice is to have the back end server function selectively put the meta data at the time of login into the custom data collection. Also, the custom data section is more secure, as only the user who logs in can read it. The JWT meta data on the other hand is less secure, i.e. you don’t want to put sensitive data here. We are in the process of building a custom JWT authenticator at our company for MongoDB Realm, hence my interest in this topic.

I hope this was useful.

Richard Krueger