Docs menu

React Native SDK

Identify users in the React Native SDK

Sign your users in with an identity token from your backend.

Leave out identity for anonymous chat.

Provide a token

To sign a user in, give the SDK a way to get an identity token from your backend, either as a callback:

TS
const identity = { getToken: () => api.fetchMentioraToken() };

or as an endpoint the SDK calls itself:

TS
const identity = {
  endpoint: "https://api.example.com/mentiora/token",
  headers: () => ({ Authorization: `Bearer ${yourAuthToken()}` }),
  body: () => ({ locale }),
};

Mentiora.configure({ widgetUrl, identity });

The SDK sends a JSON POST and accepts { "token": "…" }, { "identityToken": "…" } or a bare string. It caches the token and fetches a new one before exp.

The SDK compares identity by reference, and a new object reloads the chat. Create it outside render.

Token requirements

Your backend signs the token with an identity key from the Install tab. It is the same token the web widget uses (HS256, with sub, aud: "mentiora", iat and exp), with one extra rule: in the app, exp - iat must be at most 3600 seconds. Keep the identity key on your server.

Sign-out

Call Mentiora.logout() when the user signs out, and detach their device token in your backend. logout() starts a new anonymous user on the device and clears the cached token.

Once a user has signed in, the device stays marked as signed in until logout(). Until then, opening the chat without identity fails with an identityError event.