Narrated 'Umar bin Al-Khattab (May Allah be pleased with him), reported:
Messenger of Allah (ﷺ) said, "The deeds are considered by the intentions, and a person will get the reward according to his intention. So whoever emigrated for Allah and His Messenger, his emigration will be for Allah and His Messenger; and whoever emigrated for worldly benefits or for a woman to marry, his emigration would be for what he emigrated for".[Al-Bukhari and Muslim].
Arabic/English book reference: Book 1, Hadith 1