This is a wonderful question! And it’s actually regarding something I’ve done quite a bit of research regarding.
Here’s the thing: from what I’ve gathered, it’s more important to have representation than it is to not offend people. It’s better to show that these people exist than trying to account for being offensive. Obviously, it’s important to do your research and avoid being offensive if it’s at all possible, but literally everything you write will offend someone in some way.
People crave representation. It’s exciting to discover a character that is like you in some fundamental way.
If that character is unintentionally a bit offensive, yes, it will bother people, but it’s better that you tried than to pretend that that group doesn’t exist at all.
I think it’s important to have a variety of types of people in your stories, and most people understand that it’s difficult to step into the shoes of someone of a different race, sexuality, or whatever else. People will tell you how it’s offensive, and you can try to do better next time if it seems feasible.
It can help to interview people of that group, as well. They can tell you what it’s like to live as a certain type of person. There are different types of prejudice that all peoples must deal with at some point in your life, and as someone who is not a member of that group, it is unlikely that you have accounted for all of them.
This might seem like a really simplistic answer, but at the heart of the matter, it is what is the most true.
Respond to criticism as kindly and constructively as possible–if at all–and do your research. If you do those things, then you will be okay.