> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-rn-guide-message-privately.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Methods

> Static methods on CometChatUIKit for initialization, authentication, and message sending.

<Accordion title="AI Integration Quick Reference">
  | Field   | Value                                                                     |
  | ------- | ------------------------------------------------------------------------- |
  | Class   | `CometChatUIKit`                                                          |
  | Package | `@cometchat/chat-uikit-react`                                             |
  | Usage   | Static methods — no instantiation needed                                  |
  | Note    | You must call `init()` and `login()` before rendering `CometChatProvider` |
</Accordion>

## Overview

`CometChatUIKit` is a static class that provides imperative methods for SDK initialization, authentication, and message sending. The UI Kit wraps the [Chat SDK](/sdk/javascript/overview) methods to manage internal eventing and keep UI components synchronized. Use these wrapper methods instead of raw SDK calls.

You must call `CometChatUIKit.init()` and `CometChatUIKit.login()` (or `loginWithAuthToken()`) before mounting `CometChatProvider`. These methods are also useful for:

* Sending messages programmatically outside the composer
* Checking initialization/login state

***

## Initialization

### `CometChatUIKit.init(settings)`

Initialize the CometChat SDK and UIKit.

```tsx theme={null}
import { CometChatUIKit, UIKitSettingsBuilder } from "@cometchat/chat-uikit-react";

const settings = new UIKitSettingsBuilder()
  .setAppId("APP_ID")
  .setRegion("us")
  .setAuthKey("AUTH_KEY")
  .subscribePresenceForAllUsers()
  .build();

const user = await CometChatUIKit.init(settings);
// user is non-null if an existing session was found
```

| Parameter  | Type            | Description                      |
| ---------- | --------------- | -------------------------------- |
| `settings` | `UIKitSettings` | Built via `UIKitSettingsBuilder` |

**Returns:** `Promise<CometChat.User | null>` — the logged-in user if a session exists, otherwise null.

**What it does:**

1. Initializes the CometChat SDK with app settings
2. Sets source metadata for analytics
3. Creates the plugin registry (default + user plugins)
4. Initializes the localization singleton
5. Resumes existing session (if any)
6. Initializes Calls SDK (if enabled)

### Setting Session Storage Mode

By default, session data is stored in `localStorage`. To use `sessionStorage` instead, configure it during initialization via the `UIKitSettingsBuilder`:

```tsx theme={null}
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatUIKit, UIKitSettingsBuilder } from "@cometchat/chat-uikit-react";

const settings = new UIKitSettingsBuilder()
  .setAppId("APP_ID")
  .setRegion("REGION")
  .setAuthKey("AUTH_KEY")
  .setStorageMode(CometChat.StorageMode.SESSION)
  .build();

CometChatUIKit.init(settings).then(() => {
  console.log("Initialization completed with session storage");
});
```

When using `sessionStorage`, configure it in your `UIKitSettingsBuilder` before calling `CometChatUIKit.init()`:

```tsx theme={null}
<CometChatProvider>
  <App />
</CometChatProvider>
```

<Note>
  Session storage is cleared when the browser tab is closed. Use this mode if you want users to re-authenticate on every new tab/session.
</Note>

***

## Authentication

### `CometChatUIKit.login(uid)`

Log in a user by UID. Requires `authKey` in UIKitSettings.

```tsx theme={null}
const user = await CometChatUIKit.login("superhero1");
```

| Parameter | Type     | Description    |
| --------- | -------- | -------------- |
| `uid`     | `string` | The user's UID |

**Returns:** `Promise<CometChat.User>`

### `CometChatUIKit.loginWithAuthToken(authToken)`

Log in with a server-generated auth token. Preferred for production.

```tsx theme={null}
const user = await CometChatUIKit.loginWithAuthToken(token);
```

| Parameter   | Type     | Description                 |
| ----------- | -------- | --------------------------- |
| `authToken` | `string` | Server-generated auth token |

**Returns:** `Promise<CometChat.User>`

### `CometChatUIKit.logout()`

Log out the current user.

```tsx theme={null}
await CometChatUIKit.logout();
```

**Returns:** `Promise<void>`

***

## User Management

Both methods require `authKey` in your UIKitSettings — they throw if it is missing. Intended for development/testing; in production, create and update users server-side via the REST API.

### `CometChatUIKit.createUser(user)`

Create a new user.

```tsx theme={null}
import { CometChat } from "@cometchat/chat-sdk-javascript";

const user = new CometChat.User("new-uid");
user.setName("Alice");

const created = await CometChatUIKit.createUser(user);
```

| Parameter | Type             | Description        |
| --------- | ---------------- | ------------------ |
| `user`    | `CometChat.User` | The user to create |

**Returns:** `Promise<CometChat.User>`

### `CometChatUIKit.updateUser(user)`

Update an existing user.

```tsx theme={null}
const user = new CometChat.User("existing-uid");
user.setName("Alice Updated");

const updated = await CometChatUIKit.updateUser(user);
```

| Parameter | Type             | Description        |
| --------- | ---------------- | ------------------ |
| `user`    | `CometChat.User` | The user to update |

**Returns:** `Promise<CometChat.User>`

***

## State Getters

### `CometChatUIKit.getLoggedInUser()`

Get the currently logged-in user (synchronous).

```tsx theme={null}
const user = CometChatUIKit.getLoggedInUser();
```

**Returns:** `CometChat.User | null`

### `CometChatUIKit.isInitialized()`

Check if the SDK has been initialized.

```tsx theme={null}
if (CometChatUIKit.isInitialized()) { ... }
```

**Returns:** `boolean`

### `CometChatUIKit.isCallingReady()`

Check if the Calls SDK is ready.

**Returns:** `boolean`

### `CometChatUIKit.getPluginRegistry()`

Get the plugin registry instance.

**Returns:** `CometChatPluginRegistry | null`

### `CometChatUIKit.getSettings()`

Get the UIKitSettings used during initialization.

**Returns:** `UIKitSettings | null`

### `CometChatUIKit.getConversationUpdateSettings()`

Get conversation update settings fetched from the dashboard.

**Returns:** `CometChat.ConversationUpdateSettings | null`

***

## Message Sending

<Warning>
  These methods are low-level utilities. They send messages via the SDK but do **not** publish `ui:message/sent` events. This means:

  * The message won't appear in `CometChatMessageList` automatically
  * The `CometChatConversations` list won't update

  For messages to appear in the UI, use the `CometChatMessageComposer` component, or manually publish the event after sending:

  ```tsx theme={null}
  const publish = usePublishEvent();
  const msg = await CometChatUIKit.sendTextMessage(message);
  publish({ type: "ui:message/sent", message: msg, status: CometChatMessageStatus.success });
  ```
</Warning>

### `CometChatUIKit.sendTextMessage(message)`

Send a text message. Sets `muid` and `sentAt` if not already set.

```tsx theme={null}
const textMessage = new CometChat.TextMessage("receiverUid", "Hello!", "user");
const sent = await CometChatUIKit.sendTextMessage(textMessage);
```

**Returns:** `Promise<CometChat.BaseMessage>`

### `CometChatUIKit.sendMediaMessage(message)`

Send a media message (image, video, audio, file).

```tsx theme={null}
const mediaMessage = new CometChat.MediaMessage("receiverUid", file, "image", "user");
const sent = await CometChatUIKit.sendMediaMessage(mediaMessage);
```

**Returns:** `Promise<CometChat.BaseMessage>`

### `CometChatUIKit.sendCustomMessage(message)`

Send a custom message (polls, location, etc.).

```tsx theme={null}
const customMessage = new CometChat.CustomMessage("receiverUid", "user", "location", { latitude: 37.7749, longitude: -122.4194 });
const sent = await CometChatUIKit.sendCustomMessage(customMessage);
```

**Returns:** `Promise<CometChat.BaseMessage>`
