Error trying to set current member's profile to public

I’m developing a custom “accoount settings” page in wich I put a checkbox for the member to set it’s profile to public/private, but the makeProfilePublic() function is returning the following error in the backend:

{
details: {
applicationError: {
code: “COMMUNITY_JOIN_IMPOSSIBLE”,
data: {
description: “Precondition Required”
}
}
}
}

Using the frontedn function and inspecting the network tab, I can see the following response: “Joining community is not possible due to current site privacy settings”