removeRole function

String removeRole({
  1. required Entry authDatabase,
  2. required String username,
  3. required String role,
})

Implementation

String removeRole({
  required Entry authDatabase,
  required String username,
  required String role,
}){
  DbObject? account = _getAccount(
    authDatabase: authDatabase,
    username: username,
  );
  if(account != null){
    Map<String,dynamic> accountContent = account.view();
    List<dynamic> roles = accountContent["roles"];
    int index = roles.indexOf(role);
    if(0 <= index){
      account.pop(index: index, key: "roles");
      return "Role $role removed successfully.";
    }else{
      throw "Role $role not found.";
    }
  }else{
    throw "Invalid username.";
  }
}