“Actions are according to intentions, and everyone will get what was intended. Whoever migrates with an intention for Allah and His messenger, the migration will be for the sake of Allah and his Messenger. And whoever migrates for worldly gain or to marry a woman, then his migration will be for the sake of whatever he migrated for.”

Related by Bukhari & Muslim

 

Everything we do has to be intended for the sake of Allah (swt). A good action with the wrong intention will not get us any reward in the Hereafter.