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 callinglogin(), 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.
getLoggedInUser() method returns a user 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.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
- User authenticates with your backend
- Your backend calls the CometChat Create Auth Token API
- Your backend returns the Auth Token to the client
- Client uses the Auth Token to login
User Object
On successful login, the method returns a user object containing user information:Check User Login Status
You can verify if a user is currently logged in:Get User Auth Token
Retrieve the auth token of the currently logged-in user:Logout
Calllogout() when the user signs out of your application. This clears the local session and disconnects from CometChat services.