Authentication
In order to use the features of Sendbird Chat SwiftUI in your client apps, a SendbirdUI
instance must be initiated in each client app through user authentication with the Sendbird server. The instance communicates and interacts with the server using an authenticated user account, and is allowed to use the SwiftUI's features. This page explains how to authenticate your user with the server.
Prerequisites
- Sendbird SwiftUI should be initialized, for the details please refer Getting Started.
Overview
Authentication is required to use Sendbird’s features and there are three methods:
- Guest Login: A token is not required. However, this method is not recommended for production due to security vulnerabilities. You use a UserID only to authenticate.
- You can turn off this feature in Access token permission.
- Access Token: A token that does not expire. It can be generated by Platform API or from the Dashboard.
- Session Token: Highly recommended for enhanced security.
Note: This document does not cover session handling. Please refer to this SDK document for more details.
Basic
In Sendbird SwiftUI, the basic way to authenticate is as follows:
- Set and store a UserID and token.
- When accessing a screen, Sendbird SwiftUI communicates with the Sendbird server using those credentials. This means Sendbird SwiftUI handles authentication internally and automatically.
How You Can Set the User ID and Token
Manual Connection
You can manually connect to the Sendbird server and retrieve user information without accessing Sendbird SwiftUI’s screens. This is commonly required when you need to call SDK functions outside of Sendbird SwiftUI’s screens.
Example Use Case
One example is registering a push token when a user logs into your service. To ensure notifications from Sendbird are not missed, you need to register the push token at the time of service login.
Logout
Call the SendbirdUI.disconnect()
method if the user requests to log out. If a user has been logged out and thus disconnected from the server, they will no longer receive messages.
NOTE: You must call
unregisterPushToken
to ensure the user does not receive notifications anymore.