Skip to main content
Before users can make or receive calls, they must be authenticated with the CometChat Calls SDK. This guide covers the login and logout methods.
Sample UsersCometChat provides 5 test users: cometchat-uid-1, cometchat-uid-2, cometchat-uid-3, cometchat-uid-4, and cometchat-uid-5.

Check Login Status

Before calling login(), check if a user is already logged in using getLoggedInUser(). The SDK maintains the session internally, so you only need to login once per user session.
The getLoggedInUser() method returns a CallUser object if a user is logged in, or null if no session exists.

Login with UID and API Key

This method is suitable for development and testing. For production apps, use Auth Token login instead.
Security NoticeUsing the API Key directly in client code is not recommended for production. Use Auth Token authentication for enhanced security.

Login with Auth Token

This is the recommended authentication method for production applications. The Auth Token is generated server-side, keeping your API Key secure.

Auth Token Flow

  1. User authenticates with your backend
  2. Your backend calls the CometChat Create Auth Token API
  3. Your backend returns the Auth Token to the client
  4. Client uses the Auth Token to login

CallUser Object

On successful login, the callback returns a CallUser object containing user information:

Logout

Call logout() when the user signs out of your application. This clears the local session and disconnects from CometChat services.

Error Handling

Common authentication errors: