> For the complete documentation index, see [llms.txt](https://docs.sentiance.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sentiance.com/sdk/appendix/user-creation-and-management.md).

# User Creation and Management

For the SDK to perform detections and deliver valuable insights, a Sentiance user must first be created. Each Sentiance user is linked to a unique user in your system. When creating a Sentiance user, you must provide an identifier that uniquely represents the user on your side.

Each Sentiance app environment is completely segregated, meaning no data or SDK users can be shared across environments or Sentiance apps. The SDK on the user's device is linked to a specific Sentiance app environment during user creation, so the API key you use determines the environment.

{% hint style="warning" %}
Always use the API key matching the intended Sentiance environment when creating a SDK user.
{% endhint %}

Linking a user requires a server-to-server interaction. The Sentiance SDK does not accept your system's user identifier directly from the app, since a mobile app is not considered a trusted source. Instead, your backend must send the unique user identifier to Sentiance, authorized using a Sentiance API key.

If the provided unique user identifier is already linked to an existing Sentiance user in the target environment, that user is restored on the device. Otherwise, a new Sentiance user is created.

{% stepper %}
{% step %}

### User Creation flow

You provide to us your unique user identifier when making an authentication code request. In return, Sentiance will provide to you a short-lived authentication code, which you will then use to create a Sentiance user on the device.

The steps are as follows:

1. When decided to create a Sentiance user, contact your backend and request a Sentiance authentication code.
2. On your backend, create a corresponding request towards the Sentiance backend, which will include your user's unique identifier. This request is authenticated using a Sentiance [API Key](/sdk/appendix/request-authentication.md).
3. Retrieve the authentication code provided by Sentiance and forward it to your app.
4. In the app, create a Sentiance user by passing this authentication code.

Check out [User Creation](/getting-started/sdk-integration/4.-user-creation.md) for detailed instructions

{% endstep %}

{% step %}

### Switching a user to a different environment

Linking happens only at user creation, there is no method to move an existing user between environments. To switch a user to a different environment, they must go through the user creation flow again, using the target environment's API key when requesting an authentication code from your backend.

Only one SDK user can exist per app instance at a time. If a user is already active and authenticated on the device, attempting to create a new one will fail. To free up the instance for a new user, call the SDK's `reset` method first. This clears all SDK data and removes the current user instance from the device, freeing it for a new user to be authenticated.

{% hint style="info" %}
**The core rule**

No new SDK user can be created while a user instance is still active in the same app instance, the existing one must be cleared first.
{% endhint %}
{% endstep %}

{% step %}

### Multi-Device support

A Sentiance user can only be active on one device at a time.

If a user is already authenticated on one device and authenticates on another, the new device takes priority, and the user will be deactivated on the previous device.

The only exception to this is when the existing active user instance is on a mobile phone, and you attempt to restore the user on a tablet device. In this case, Sentiance will prioritize the mobile phone , and keep the user active.

When a user is deactivated:

* The SDK stops performing detections
* The user must re-authenticate before detections can resume

{% endstep %}

{% step %}

### User Deletion

#### From the Device

To remove all SDK data and user-related information from a device, call the `reset()` method on the SDK’s core instance.

This will remove:

* Stored SDK data
* Settings and configurations
* Detection data
* All user-related data on the device

**Important Notes**

* During an ongoing reset operation, other SDK method calls may be ignored, fail, or return default values.
* Make sure the app stays in the foreground while the reset is in progress, for example by keeping an activity open or a foreground service running. If the app is backgrounded or terminated, the SDK cannot guarantee that the reset will complete successfully.
* The `reset()` method can be called even if the SDK has not been initialized.

#### From the Sentiance Platform

Deleting a user from the Sentiance platform must be done via server-to-server communication.

User Deletion can be achieved by using the [delete\_user](https://graphqldocs.sentiance.com/#mutation-delete_user) mutation. An [API Key](/sdk/appendix/request-authentication.md#api-keys) with the [USER\_DELETE](/sdk/appendix/request-authentication.md) scope must be used to call the deletion mutation.

When initiating a deletion request, a `request_id` is returned in the response. This ID is intended for debugging purposes only and can be shared with Sentiance support if needed.

After the deletion request has been successfully completed, you should [reset the SDK on the user’s device](#from-the-device). Resetting the SDK will:

* Stop all SDK operations
* Remove all user-related data from the device
  {% endstep %}
  {% endstepper %}
