Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
quran:29:10

And of the people are some who say, "We believe in Allah," but when one ˹of them˺ is harmed for ˹the cause of˺ Allah, they consider the trial of the people as ˹if it were˺ the punishment of Allah. But if victory comes from your Lord, they say, "Indeed, We were with you." Is not Allah most knowing of what is within the breasts of all creatures?  

And among people there are those who say, ‘We believe in God’, but if such ˹a person˺ suffers hurt in God’s cause, he takes people’s persecution, that is, their harming of him, to be ˹the same˺ as God’s chastisement, in terms of his fear of it, and so he obeys them and behaves hypocritically. Yet if (la-in: the lām is for oaths) there comes help, to believers, from your Lord, and they take spoils, they will assuredly say (la-yaqūlunna: the ˹final˺ nūn ˹of the indicative˺ has been omitted because of the other nūn coming after it, and likewise the wāw, indicating the plural person ˹has been replaced by a damma˺, because of two unvocalised consonants coming together), ‘We were indeed with you’, in faith, so give us a share of the booty. God, exalted be He, says: Does God not know best what is in the breasts of all creatures?, ˹what is˺ in their hearts of faith or hypocrisy? Indeed ˹He does˺.
القرآن:٢٩:١٠

وَمِنَ النَّاسِ مَنْ يَقُولُ آمَنَّا بِاللَّهِ فَإِذَا أُوذِيَ فِي اللَّهِ جَعَلَ فِتْنَةَ النَّاسِ كَعَذَابِ اللَّهِ وَلَئِنْ جَاءَ نَصْرٌ مِنْ رَبِّكَ لَيَقُولُنَّ إِنَّا كُنَّا مَعَكُمْ ۚ أَوَلَيْسَ اللَّهُ بِأَعْلَمَ بِمَا فِي صُدُورِ الْعَالَمِينَ  

{ومن الناس من يقول آمنا بالله فإذا أوذي في الله جعل فتنة الناس} أي أذاهم له {كعذاب الله} في الخوف منه فيطيعهم فينافق {ولئن} لام قسم {جاء نصرٌ} للمؤمنين {من ربك} فغنموا {ليقولنَّ} حذفت منه نون الرفع لتوالي النونات والواو ضمير الجمع لالتقاء الساكنين {إنا كنا معكم} في الإيمان فأشركونا في الغنيمة قال تعالى: {أوَ ليس الله بأعلم} أي بعالم {بما في صدور العالمين} بقلوبهم من الإيمان والنفاق؟ بلى.