Kazantzakis' historical fiction Freedom and Death, written in the 1940s but recalling his childhood in the 1880s, features both Christians making scatological references to the "prophet's beard", and Muslims swearing by the prophet's beard; that suggests to me the reference isn't a pure Western invention (Greeks under Ottoman rule aren't quite Western), although Kazantzakis did read plenty of Western European fiction before writing his novel:
Χότζα, φώναξε, στο Μεγάλο Κάστρο εγώ κάνω κουμάντο, θα σου βάλω, μά τα γένια
του Προφήτη, στουμούχα, ως καθώς βάζουν στους δαγκανιάρηδες σκύλους, να
σωπάσεις! "Imam, [the pasha] yelled, I'm the boss of Kastro [= Iraklion]: by
the beard of the prophet, I'll gag you like a rabid dog."
The scatological references by Greek Christians ("I spit on, I crap on") are frequent and old enough to suggest to me they were authentic; but they don't prove that Muslims actually swore by the prophet's beard.
https://www.redensarten-index.de/suche.php?suchbegriff=~~Beim%20Barte%20des%20Propheten!&suchspalte%5B%5D=rart_ou says the saying is documented in the West since the 18th century (which includes Mozart), but is equivocal about whether it is authentic, or a misconstrual of generic swearing by beards.
M. Zwemer's 1948 article "Hairs of the Prophet" (which is cited in books on Google Books, so it's not a modern confection) claims that
The sanctity of Mohammed’s beard as token of manhood and dignity is
recognized in common oaths. Even as the Arabs swear by their own lives
or by their beards (walahyeti), so more solemnly the Moslem community
swears by the beard of their Prophet (lahyet al-nabi). One hears this
oath everywhere in the Near East.
I hesitate to call this definitive evidence, though, because searches for Arabic lahyet al-nabi/ لحية النبي or Turkish sakalı şerif don't turn anything that looks like an oath on Google (at least not in the first 3 pages' worth that I ran through Google Translate). I'd have expected more if the phrase was in current use even in the 19th century.
There are travelogues from the 1830s through 1850s by Europeans that clearly cite Muslims swearing by the prophet's beard: 1833 Palestine, 1836 Istanbul, 1855 Saudi Arabia (Richard Burton).
The problem here is that both Islamic and Christian sources can be called into quesstion. Islamic sources would censor out blasphemous references. Christian sources would exoticise Muslim oaths. I find the 1830s Christian testimony convincing, as travelogues rather than historical fiction; but @NSNoob does not, and I appreciate why.
The best scholarly evidence I have found is this recent article on Jordanian Arabic oaths. There's plenty of swearing by the prophet, and there's plenty of swearing by beards; but the source doesn't mention any swearing by the prophet's beard.