Docs Menu
Docs Home
/ /
Atlas Device SDKs
/ /

Manage User Metadata - Kotlin SDK

On this page

  • Read a User's Metadata
  • Serializable User Metadata
  • Configure User Metadata
  • Update User Metadata

This page describes how to manage user metadata for an authorized App Services App user using the Realm Kotlin SDK. For more information, refer to Authentication Provider Metadata in the App Services documentation.

Atlas App Services can read user metadata from authentication providers. Then, App Services exposes each user's data in a field of their User object. For example, you might want to access a user's name, email, birthday, or gender.

You can read the user metadata of a currently logged-in user through that user's User object. You cannot edit user metadata through a User object.

To read the data, call the profileAsBsonDocument method on the User object of a logged-in user:

// Log in a user
val user = app.login(Credentials.emailPassword(email, password))
// Access the user's metadata
val userEmail = user.profileAsBsonDocument()["email"]
Log.i("The logged-in user's email is: $userEmail")

User metadata options vary depending on which provider you're using and which metadata fields you enable.

Warning

User Metadata May Be Stale

Atlas App Services fetches the most recent version of user metadata when a user logs in. If the user changes their email address or profile photo with a login provider, for example, those changes do not update in user metadata until the user logs in again. Because we cache credentials and enable you to bypass the login flow, user metadata may become stale unless you force the user to log in again.

New in version 1.9.0.

Kotlin SDK version 1.9.0 introduced an API that supports:

  • A limited but stable EJSON encoder for user metadata returned by User.profileAsBsonDocument()

  • An experimental EJSON encoder that supports full document serialization for user metadata returned by the User.profile() extension method. This encoder and method requires experimental opt-in.

You must add the official Kotlin Serialization library to your project to use Realm Kotlin SDK's EJSON serialization. For more information, refer to Serialization.

You can only read user metadata from the client app that you have configured on the App Services application.

You can configure the user metadata you request from an authentication provider. You do this directly on the authentication provider's configuration. For more details on which metadata fields you can use, see the provider details:

You can change which metadata fields you have configured by editing the provider's configuration.

User metadata that you access through the authentication provider is read-only data. You cannot update or edit user metadata that comes from this source.

If you would like to give a user the option the update their metadata from within your client app, use custom user data, instead.

Back

Manage Custom User Data

Next

Sync Device Data