> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sagepilot.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Identity

> Identify signed-in app users and clear Sagepilot state on logout.

Call `identify()` when you know the signed-in app user.

```ts theme={null}
await SagepilotChat.identify({
  userId: user.id,
  email: user.email,
  name: user.name,
  phone: user.phone,
  customProperties: {
    plan: "pro",
    storeId: "store_123"
  }
});
```

Use `behavior.waitForIdentifyBeforeComposer: true` for authenticated support flows where the composer should wait for an in-flight identity request before opening.

```ts theme={null}
await SagepilotChat.configure({
  key: "workspace_id:channel_id",
  behavior: {
    waitForIdentifyBeforeComposer: true
  }
});

const identifyPromise = SagepilotChat.identify({
  userId: user.id,
  email: user.email
});

const opened = await SagepilotChat.presentMessageComposer("I need help with my order");
await identifyPromise;
```

`presentMessageComposer()` waits only while `identify()` is already pending. If identity is not pending, it opens immediately.

You can inspect local identity state with `SagepilotChat.getIdentityState()` or `useSagepilotChat().identity`. The state includes `identified`, `pending`, and `customer`.

## Identity verification

If identity verification is enabled for your workspace, generate `userHash` on your server and pass only the generated hash to the app:

```ts theme={null}
await SagepilotChat.identify({
  userId: user.id,
  email: user.email,
  userHash: serverGeneratedUserHash
});
```

<Warning>
  Never generate `userHash` in the mobile app with a signing secret.
</Warning>

## Logout

When the app user signs out, clear Sagepilot identity/session state:

```ts theme={null}
await SagepilotChat.logout();
SagepilotChat.destroy();
```

`logout()` removes the known customer identity from the current SDK session. `destroy()` stops polling, clears in-memory state, and removes SDK listeners.
