Context is everything. If it's set in modern times or something analogous to that, then use modern language. If it's set in some historical era or analogue to that, then strive for some sort of verisimilitude. All it takes is a sprinkle. My model for that is Patrick O'Brian, who was a master at it, fitting cursing not only to the times but also to the class and background of the speaker.
When dealing with a completely invented world, things get trickier. Many invented worlds fall into that "analogue" category and are obviously similar to a real historical era (steampunk, e.g.). But some are quite outside the pale, and there the author must find their own way. Very broadly, the narrator ought not swear more than the characters. First person narrator is the huge exception there; a first-person narrator is essentially another character and so should fit properly into the larger context.
Beyond or behind all that is the matter of audience. If the target is a young reader, then the rules might change, or at least an individual author might make different choices. Personally, were I to write a modern YA fantasy, I'd stay well away from swearing or any sort of jargon because the vocabulary of the young shifts so often and subtly. If the adults are aware of it, it's already out of date.
All of which is to say ... it depends.