getLoggedInUser static method

Future<User?> getLoggedInUser({
  1. dynamic onSuccess(
    1. User
    )?,
  2. dynamic onError(
    1. CometChatException
    )?,
})

getLoggedInUser checks if any session is active and retrieves the User data of the logged in user

Implementation

static Future<User?> getLoggedInUser(
    {dynamic Function(User)? onSuccess,
    dynamic Function(CometChatException)? onError}) async {
  User? user = await CometChat.getLoggedInUser(onSuccess: (user) {
    CometChatUIKit.loggedInUser = user;

    //executing the custom onSuccess handler
    if (onSuccess != null) {
      try {
        onSuccess(user);
      } catch (e) {
        if (kDebugMode) {
          debugPrint("failed to execute onSuccess callback");
        }
      }
    }
  }, onError: (error) {
    //executing the custom onError handler
    if (onError != null) {
      try {
        onError(error);
      } catch (e) {
        if (kDebugMode) {
          debugPrint("failed to execute onError callback");
        }
      }
    }
  });
  return user;
}