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

Use getLoggedInUser() to find out whether — and which — user has a persisted session, for example at app launch to decide whether to show your login screen. It returns a CallUser object if a user is logged in, or null if no session exists. You never need it as a guard before login(): calling login() is always safe — if the same user is already logged in it returns the existing session without a network round trip, and if a different user is logged in the SDK switches to the new user automatically (see Switching Users).
Check who is logged in, not just whetherOn a shared or reused device, the persisted session may belong to a different user. If your app skips its own login flow because getLoggedInUser() is non-null, compare the returned UID against your app’s current account first — otherwise calls are silently placed as the previous user.

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

Switching Users

On a shared or reused device, call login() with the new user’s credentials — there is no need to check or clear the previous session yourself. If a different user is logged in, the SDK logs them out automatically before logging the new user in. Calling login() for the user who is already logged in simply returns the existing session.

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; the SDK stays initialized, so the next user can login() directly.

Error Handling

Common authentication errors: