Calls / React Native
Calls React Native v1
Calls React Native
Calls
React Native
Home
/
Calls
/
React Native

Authentication

In order to use the features of the Calls SDK in your apps, user authentication with the Sendbird server must be initiated through the SendbirdCalls.authenticate() method. To receive calls when an app is in the background or closed, a user’s device registration token must be registered to the server. A device registration token can be registered by passing it as an argument to a parameter in the Authenticate() method when authenticating a user.


Initialize the Calls SDK with Application ID

As shown below, the SendbirdCalls instance must be initialized when a client app is launched. After installing the Calls SDK, initialize the SendbirdCalls instance using your application ID, which you can retrieve by signing into Sendbird Dashboard.

If the instance is initialized with a different application ID, all existing call-related data in a client app will be cleared and the SendbirdCalls instance will be initialized again with the new application ID.

import { SendbirdCalls } from '@sendbird/calls-react-native';

SendbirdCalls.initialize(APP_ID);

Authenticate to the Sendbird server

In order to use the interfaces and methods provided in the SendbirdCalls instance, a user must be connected to the Sendbird server through authentication. Without authentication, calling the methods of the Calls SDK will not work in a user’s client app. This means that if a user performs actions such as accepting an incoming call before authentication, the user will receive errors from the Sendbird server.

You can either authenticate a user by calling the SendbirdCalls.authenticate() method or with their user ID, which is found on Sendbird Dashboard to connect to the Sendbird server.

import { SendbirdCalls } from '@sendbird/calls-react-native';

try {
  const user = await SendbirdCalls.authenticate({
    userId: 'USER_ID',
    accessToken: 'ACCESS_TOKEN'
  });
} catch (e) {
  // Handle error.
}

Deauthenticate from the Sendbird server

By using the SendbirdCalls.deauthenticate() method, you can deauthenticate a user from the Sendbird server. It will clear all current direct calls, session keys, and user information from a user’s client app. This can also be considered as logging out from the server.

import { SendbirdCalls } from '@sendbird/calls-react-native';

try {
    await SendbirdCalls.deauthenticate();
} catch (e) {
    // Handle error.
}