Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions chat-call.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ npx @cometchat/skills add
<Card title="Android" icon={<img src="/docs/images/icons/android.svg" alt="Android" />} href="/sdk/android/overview" horizontal />
<Card title="Flutter" icon={<img src="/docs/images/icons/flutter.svg" alt="Flutter" />} href="/sdk/flutter/overview" horizontal />
<Card title="Ionic" icon={<img src="/docs/images/icons/ionic.svg" alt="Ionic" />} href="/sdk/ionic/overview" horizontal />
<Card title="Unreal Engine" icon={<img src="/docs/images/icons/unreal.svg" alt="Unreal Engine" />} href="/sdk/unreal/overview" horizontal />
</CardGroup>
</div>

Expand Down
39 changes: 39 additions & 0 deletions docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -4613,6 +4613,45 @@
}
]
},
{
"dropdown": "Unreal Engine",
"icon": "/images/icons/unreal.svg",
"pages": [
"sdk/unreal/overview",
"sdk/unreal/setup",
"sdk/unreal/key-concepts",
{
"group": "Authentication",
"pages": [
"sdk/unreal/authentication"
]
},
{
"group": "Messaging",
"pages": [
"sdk/unreal/send-message",
"sdk/unreal/receive-messages",
"sdk/unreal/real-time-events",
"sdk/unreal/typing-indicators",
"sdk/unreal/delivery-read-receipts",
"sdk/unreal/connection-status"
]
},
{
"group": "Users & Groups",
"pages": [
"sdk/unreal/users",
"sdk/unreal/groups"
]
},
{
"group": "Reference",
"pages": [
"sdk/unreal/reference"
]
}
]
},
{
"dropdown": "Ionic (Legacy)",
"icon": "/images/icons/ionic.svg",
Expand Down
4 changes: 4 additions & 0 deletions images/icons/unreal.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/unreal_chat_sample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
267 changes: 267 additions & 0 deletions sdk/unreal/authentication.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
---
title: "Authentication"
description: "Log users in and out of CometChat in your Unreal Engine project."
---

## Create User

Before you log in a user, the user must exist in CometChat.

1. **For proof of concept / MVPs**: Create users via the [CometChat Dashboard](https://app.cometchat.com).
2. **For production apps**: Use the [Create User REST API](https://api-explorer.cometchat.com/reference/creates-user) when your user signs up.

<Note>
**Sample Users**

CometChat provides 5 pre-created users for testing: `cometchat-uid-1`, `cometchat-uid-2`, `cometchat-uid-3`, `cometchat-uid-4`, and `cometchat-uid-5`.
</Note>

---

## Login using Auth Key

<Info>
This authentication method is ideal for **proof-of-concept** development or early-stage apps. For production environments, we recommend using an **Auth Token** instead of an Auth Key for enhanced security.
</Info>

### Auth Flow

```mermaid
flowchart LR
A["Configure"] --> B["Bind Delegates"] --> C["Login Async"]
C -->|"Success"| D["User Authenticated"]
C -->|"Failure"| E["Handle Error"]
D --> F["SDK Ready — Send messages, fetch data"]

style A fill:#333,stroke:#666,color:#fff
style B fill:#333,stroke:#666,color:#fff
style C fill:#444,stroke:#888,color:#fff
style D fill:#333,stroke:#666,color:#fff
style E fill:#555,stroke:#999,color:#ccc
style F fill:#333,stroke:#666,color:#fff
```

The Login node authenticates a user with CometChat. You should call it:

1. When the user is logging in for the first time
2. When `IsLoggedIn` returns `false`

<Tabs>
<Tab title="Blueprint">
1. Get a reference to the **CometChat Subsystem**
2. Call the **Login Async** node
3. Wire the **On Success** and **On Failure** pins

| Parameter | Type | Description |
| --------- | ---- | ----------- |
| Uid | `FString` | The unique ID of the user to log in |
| Auth Key | `FString` | Your CometChat Auth Key |
</Tab>
<Tab title="C++">
```cpp
#include "CometChatSubsystem.h"
#include "AsyncActions/CometChatLoginAction.h"

void AMyActor::BeginPlay()
{
Super::BeginPlay();

// 1. Configure the SDK (do this once)
UCometChatSubsystem* Chat = GetGameInstance()->GetSubsystem<UCometChatSubsystem>();
Chat->Configure(TEXT("YOUR_APP_ID"), TEXT("us"));

// 2. Bind real-time events before login
Chat->OnMessageReceived.AddDynamic(this, &AMyActor::OnMessage);

// 3. Login
if (!Chat->IsLoggedIn())
{
auto* Login = UCometChatLoginAction::LoginAsync(
this,
TEXT("cometchat-uid-1"),
TEXT("YOUR_AUTH_KEY")
);
Login->OnSuccess.AddDynamic(this, &AMyActor::OnLoginSuccess);
Login->OnFailure.AddDynamic(this, &AMyActor::OnLoginFailed);
Login->Activate();
}
}

void AMyActor::OnLoginSuccess()
{
UE_LOG(LogTemp, Log, TEXT("Login successful!"));
}

void AMyActor::OnLoginFailed(const FString& Error)
{
UE_LOG(LogTemp, Error, TEXT("Login failed: %s"), *Error);
}
```
</Tab>
</Tabs>

<Warning>
**UID format**: UIDs can be alphanumeric with underscores and hyphens. Spaces, punctuation, and other special characters are not allowed.
</Warning>

---

## Login using Auth Token

<Info>
This is the **recommended authentication method for production** apps. Auth Tokens are generated server-side using the CometChat REST API and provide enhanced security since your Auth Key is never exposed on the client.
</Info>

### How Auth Tokens Work

```mermaid
flowchart LR
A["Your Backend"] --> B["CometChat REST API"]
B -->|"Returns Auth Token"| A
A -->|"Sends Token to Client"| C["Unreal Client"]
C --> D["Login with Auth Token"]
D -->|"Success"| E["User Authenticated"]
D -->|"Failure"| F["Handle Error"]

style A fill:#333,stroke:#666,color:#fff
style B fill:#333,stroke:#666,color:#fff
style C fill:#444,stroke:#888,color:#fff
style D fill:#444,stroke:#888,color:#fff
style E fill:#333,stroke:#666,color:#fff
style F fill:#555,stroke:#999,color:#ccc
```

1. Your backend calls the [Create Auth Token REST API](https://api-explorer.cometchat.com/reference/create-authtoken) with the user's UID
2. The API returns an Auth Token
3. Your backend sends the token to the Unreal client
4. The client calls `LoginWithAuthTokenAsync` with the token

<Tabs>
<Tab title="Blueprint">
1. Get a reference to the **CometChat Subsystem**
2. Call the **Login With Auth Token Async** node
3. Wire the **On Success** and **On Failure** pins

| Parameter | Type | Description |
| --------- | ---- | ----------- |
| Auth Token | `FString` | The auth token received from your backend |
</Tab>
<Tab title="C++">
```cpp
#include "CometChatSubsystem.h"
#include "AsyncActions/CometChatLoginWithAuthTokenAction.h"

void AMyActor::LoginWithToken(const FString& AuthToken)
{
UCometChatSubsystem* Chat = GetGameInstance()->GetSubsystem<UCometChatSubsystem>();

if (!Chat->IsLoggedIn())
{
auto* Login = UCometChatLoginWithAuthTokenAction::LoginWithAuthTokenAsync(
this,
AuthToken
);
Login->OnSuccess.AddDynamic(this, &AMyActor::OnLoginSuccess);
Login->OnFailure.AddDynamic(this, &AMyActor::OnLoginFailed);
Login->Activate();
}
}

void AMyActor::OnLoginSuccess()
{
UE_LOG(LogTemp, Log, TEXT("Auth token login successful!"));
}

void AMyActor::OnLoginFailed(const FString& Error)
{
UE_LOG(LogTemp, Error, TEXT("Auth token login failed: %s"), *Error);
}
```
</Tab>
</Tabs>

<Warning>
**Security**: Never hardcode Auth Tokens in your client. Always fetch them from your backend at runtime.
</Warning>

---

## Check Login State

Before performing operations, you can check whether a user is currently logged in.

<Tabs>
<Tab title="Blueprint">
Call the **Is Logged In** node on the CometChat Subsystem. It returns a `bool`.
</Tab>
<Tab title="C++">
```cpp
UCometChatSubsystem* Chat = GetGameInstance()->GetSubsystem<UCometChatSubsystem>();

if (Chat->IsLoggedIn())
{
// User is authenticated — safe to send messages, fetch data, etc.
}
```
</Tab>
</Tabs>

---

## Logout

Logs the current user out and disconnects the real-time WebSocket.

<Tabs>
<Tab title="Blueprint">
Call the **Logout Async** node on the CometChat Subsystem. Wire the **On Success** and **On Failure** pins.
</Tab>
<Tab title="C++">
```cpp
#include "AsyncActions/CometChatLogoutAction.h"

void AMyActor::PerformLogout()
{
auto* Logout = UCometChatLogoutAction::LogoutAsync(this);
Logout->OnSuccess.AddDynamic(this, &AMyActor::OnLogoutSuccess);
Logout->OnFailure.AddDynamic(this, &AMyActor::OnLogoutFailed);
Logout->Activate();
}
```
</Tab>
</Tabs>

---

## Shutdown

To fully tear down the SDK (e.g., when your game is closing), call **Shutdown** on the Subsystem. This releases all resources and closes connections.

<Tabs>
<Tab title="Blueprint">
Call the **Shutdown** node on the CometChat Subsystem.
</Tab>
<Tab title="C++">
```cpp
UCometChatSubsystem* Chat = GetGameInstance()->GetSubsystem<UCometChatSubsystem>();
Chat->Shutdown();
```
</Tab>
</Tabs>

<Info>
You typically don't need to call Shutdown manually — the Subsystem's `Deinitialize` handles cleanup when the game instance is destroyed.
</Info>

---

## Next Steps

<CardGroup cols={2}>
<Card title="Send a Message" icon="paper-plane" href="/sdk/unreal/send-message">
Send your first text message after logging in.
</Card>
<Card title="Real-Time Events" icon="bolt" href="/sdk/unreal/real-time-events">
Listen for incoming messages and presence updates.
</Card>
</CardGroup>
Loading