Consult with the Treasure team to gain access to a pre-release version of the Treasure Launcher.

Games that are distributed via the Treasure Launcher, do not need to authenticate users via the Treasure Connect flow.

The React TDK will automatically detect if the user is using the Treasure Launcher and will use the Treasure Launcher’s authenticated account automatically.

Usage

Start a user session

To start a user session via the Treasure Launcher, use the startUserSession function from the useTreasure hook:

import { useTreasure } from "@treasure-dev/react";

const { startUserSession } = useTreasure();

Check if using Treasure Launcher

import { useTreasure } from "@treasure-dev/react";

const { isUsingTreasureLauncher } = useTreasure();

If your game is distributed via the Treasure Launcher, this will automatically call the startUserSessionViaLauncher from the @treasure-dev/launcher package.

Manual Installation

While Desktop Launcher Connect usage with the React TDK is built-in you can still install the @treasure-dev/launcher package for manual usage. You can use the functionality of the package to interact with the Treasure Launcher as described in the TDK Core documentation.

This is important if you are using the React TDK in some non-standard way, such as in an Electron application where the renderer process cannot access the process directly.

Electron Usage

If your game is built with Electron, the TDK will not be able to automatically read the auth token due to security restrictions. You will need to manually read the auth token from the getTreasureLauncherAuthToken function from the @treasure-dev/launcher package and pass the result to the TDK.

In your main process, you can listen for the get-auth-token event and return the auth token:

Main.ts
import { getTreasureLauncherAuthToken } from "@treasure-dev/launcher";

ipcMain.on("get-auth-token", (event, _arg) => {
  event.returnValue = getTreasureLauncherAuthToken();
});

And in your renderer process, you can define a getAuthToken function using the ipcRenderer API and passing that to launcherOptions in the TreasureProvider:

Main.tsx
const getAuthToken = () =>
  window.electron.ipcRenderer.sendSync("get-auth-token");

<TreasureProvider
 ...
    launcherOptions={{
        getAuthTokenOverride: getAuthToken,
    }}
>