Skip to main content
Your backend already verifies the user when they log into your app. Add one step to that handler: create a CometChat auth token for the verified user with the Create Auth Token REST API and return it in the same login response, next to the user’s other attributes. Your frontend then calls CometChat.login(authToken) with the value from the response. Nothing else changes. The REST API key stays on the server, the browser never builds or stores a token itself, and there is no separate token endpoint to secure.

Backend: add the token to your login response

Inside your existing PHP login handler, after your own credential check has succeeded:

Frontend: log in with the token from the response

In the code that already submits your login form and handles the response:
onLoggedIn() runs in both paths, so chat keeps working after a reload: getLoggedinUser() returns the cached user and no new token is needed. Code placed only in the login path would run once and never again.
Call CometChat.logout() from your app’s own logout and account-switch code, so the cached SDK user never outlives your app’s login. To cut off a user’s CometChat access from the server, for example after a password reset, revoke their tokens with Delete Auth Token or Flush Auth Tokens.
For the login patterns themselves, see Authentication; for the endpoint and headers, see Create Auth Token and REST API Authentication.