SendBird instance should be initiated in each client app through user authentication with Sendbird server. The instance communicates and interacts with the server based on an authenticated user account, and is allowed to use the Chat SDK's features. This page explains how to authenticate your user with the server.
To use our chat features, you should initialize a
SendBird instance by passing the
APP_ID of your Sendbird application as an argument to a parameter in the
new SendBird(). The
new SendBird() must be called once across your client app. Typically, initialization is implemented in the user login view.
By default, Sendbird server can authenticate a user just by a unique user ID. Then the server queries the database to check for a match upon the request for connection. If no matching user ID is found, the server creates a new user account with the user ID. The ID should be unique within a Sendbird application to be distinguished from others, such as a hashed email address or phone number in your service.
This authentication procedure is useful when in development or if your service doesn't require additional security.
Note: Go to the Event handler page to learn more about the usages of the Chat SDK's handlers and callbacks.
Note: You must connect to Sendbird server before calling any methods through the Chat SDK (apart from initializing your
SendBirdinstance). If you attempt to call a method without connecting, a
CONNECTION_REQUIRED (800101)error would be returned.
Using Chat Platform API, you can create a user along with their own access token, or issue an access token for an existing user. Once an access token is issued, a user is required to provide the access token in the
sb.connect() method which is used for logging in.
- Using the Chat API, create a Sendbird user account with the information submitted when a user signs up or in to your service.
- Save the user ID along with the issued access token to your persistent storage which is securely managed.
- When the user attempts to log in to the Sendbird application, load the user ID and access token from the storage, and then pass them to the
- Periodically replacing the user's access token is recommended to protect the account.
Note: From Settings > Application > Security > Access token permission setting in your dashboard, you are able to prevent users without an access token from logging in to your Sendbird application or restrict their access to read and write messages.
Note: For security reasons, you can also use a session token when a user logs in to Sendbird server instead of an access token. Go to the Access token vs. Session token section from the Chat API guide to learn more.
A user should be disconnected from Sendbird server when they no longer need to receive messages from an online state. However, the user will still receive push notifications for new messages from group channels they've joined.
When disconnected, all types of event handlers in a user's client app registered by the
sb.addConnectionHandler() stop receiving event callbacks from the server. Then, all internally cached data in the client app, such as the channels that are cached when the
sb.GroupChannel.getChannel() is called, are also flushed.
Note: By default, most of the data related to users, channels, and messages are internally cached in the
SendBirdinstance of a user's client app, which are retrieved by the corresponding query instances or received through the event handlers.
updateCurrentUserInfo() method, you can update a user's nickname and profile image with a URL.
Or, you can upload a profile image directly using the
Note: A user's profile image can be a
PNG(.png) file of up to 25 MB.