userLogOut method

Future<String?> userLogOut()

Implementation

Future<String?> userLogOut() async {
  String? sessionId = await CoreDb.instance().getSessionId();
  Constants.logIn = false;
  print('userLogOut sessionId = $sessionId');

  String? logout;
  var response;
  if(sessionId != null){
    response = await http.post(
        Uri.parse(
            '${APIMode.BASE_URL}api/v1/auth/logout-via-sessionid?sessionId=$sessionId'),
        body: {
          "sessionId": sessionId,
        });

    if (response.statusCode == 201) {
      logout = logoutFromJson(response.body).message;
    } else {
      onPluginError(response.body);
      logout = logoutFromJson(response.body).error;
    }
  }else{
    response = await http.post(
        Uri.parse(
            '${APIMode.BASE_URL}api/v1/auth/logout-via-sessionid?sessionId=$sessionId'),
        body: {
          "sessionId": "",
        });

    if (response.statusCode == 201) {
      logout = logoutFromJson(response.body).message;
    } else {
      onPluginError(response.body);
      logout = logoutFromJson(response.body).error;
    }
  }
  CoreDb.instance().deleteSessionId();
  CoreDb.instance().deleteAnonId();
  CoreDb.instance().deleteSubsUrl();
  CoreDb.instance().deleteUserType();
  CoreDb.instance().deleteLoginId();
  CoreDb.instance().deleteUserId();

  return logout;
}