The Messenger of Allah ﷺ saw some phlegm on the qiblah wall of the mosque while he was leading the people in prayer, so he scraped it off. When he had finished the prayer, he said, "When one of you is in prayer, Allah is before his face, so let none of you spit toward his face during prayer."
حدثنا محمد بن رمح المصري أنبأنا الليث بن سعد عن نافع
رأى رسول الله ﷺ نخامة في قبلة المسجد وهو يصلي بين يدي الناس فحتها ثم قال حين انصرف من الصلاة إن أحدكم إذا كان في الصلاة فإن الله قبل وجهه فلا يتنخمن أحدكم قبل وجهه في الصلاة
Bukhari recorded it in the Book of Adhan, in the chapter "Should one turn to attend to a matter that arises, or if he sees something," regarding prayer and other matters, in hadith 753, and Muslim recorded it in the Book of Masjids, in the chapter on the prohibition of spitting in the masjid, in hadith 547, both from the hadith of Nafi. Bukhari narrated it through the route of Layth, from him.