loginUserCallbacks static method

Future<void> loginUserCallbacks({
  1. required String jwt,
  2. dynamic onSuccess(
    1. String? id,
    2. String? externalId
    )?,
  3. dynamic onFailure()?,
})

Authenticate the current session with a JWT

@param jwt Required by the SDK - You must generate it from your backend @param onSuccess Optional - If you need to be notified about the login success @param onFailure Optional - If you need to be notified about the login failure

Implementation

static Future<void> loginUserCallbacks({
  required String jwt,
  Function(String? id, String? externalId)? onSuccess,
  Function()? onFailure,
}) async {
  if (jwt.isEmpty) {
    debugPrint('ZendeskMessaging - loginUser - jwt can not be empty');
    return;
  }

  try {
    _setObserver(
      ZendeskMessagingMessageType.loginSuccess,
      onSuccess != null
          ? (Map? args) {
              final id = args?['id'] ?? '';
              final externalId = args?['externalId'] ?? '';
              onSuccess(id, externalId);
            }
          : null,
    );
    _setObserver(
      ZendeskMessagingMessageType.loginFailure,
      onFailure != null ? (Map? args) => onFailure() : null,
    );

    await _channel.invokeMethod('loginUser', {'jwt': jwt});
  } catch (e) {
    debugPrint('ZendeskMessaging - loginUser - Error: $e}');
  }
}