User Management

All users management is through personal or anonymous Ready Player Me accounts.

State management for user management is done through the AuthManager class. AuthManager is responsible for creating, loading, and updating the user state necessary for avatar creation and updates.

AuthManager incorporates a private static session storage, which can be modified by calling specific methods to update the state. The following sections explain how to use these methods effectively.

Creating and logging in of anonymous users

Users who don't have an existing Ready Player Me account can have an anonymous account so that you can still store a list of avatars and assets for them (for your app or game only).

public static async Task LoginAsAnonymous()

This method creates an anonymous account for the user, enabling them to begin creating avatars without the need for Ready Player Me signup. The anonymous user's data is stored in the userSession variable.

 public static void SetUser(UserSession session)

This method retrieves a previous session from the session parameter. Sessions can be stored in any preferred location. The example below demonstrates storing the session in PlayerPrefs and retaining it even after the user closes the application.

Example

private async void Start()
{
    if (PlayerPrefs.HasKey("StoredSession"))
    {
        AuthManager.SetUser(JsonUtility.FromJson<UserSession>(PlayerPrefs.GetString("StoredSession")));
    }
    else
    {
        await AuthManager.LoginAsAnonymous();
    }
}

private void OnApplicationQuit()
{
    PlayerPrefs.SetString("StoredSession", JsonUtility.ToJson(AuthManager.UserSession));
}

Log in to a Ready Player Me account

public static async void SendEmailCode(string email)

This method sends a verification code to the provided email address, as shown below.

public static async Task<bool> LoginWithCode(string otp, string userIdToMerge = null)

This method accepts the verification code received via email and an optional userId parameter to merge the current anonymous account with the Ready Player Me account. By default, the parameter is set to null, indicating no account merging.

Example

The following method demonstrates how to log in a user and merge their previous anonymous account.

public void Login(string code)
{
    AuthManager.LoginWithCode(code, AuthManager.UserSession.Id);
}

Sessions for both anonymous and Ready Player Me accounts are stored in the userSession variable similarly. So, if you want to save the session for the user with a logged-in Ready Player Me account, use the same process as in the example above.

Last updated