The Prophet salAllahu ‘alayhi wa sallam once gave a sermon in which he said after thanking Allah and praising Him:
“O people! This life is the dwelling of crookedness not straightness, and the residence of sadness rather than happiness. Those who acquire knowledge in its true reality will not feel joy in times of ease, nor grieve in times of hardship. Verily, Alláh the Exalted has created this life as a test and the Hereafter as the dwelling of recompense. He made the test of this life a reason behind earning the reward of the Hereafter and the reward in the Hereafter as compensation for the test in this life. He takes so that He gives and tests so that He recompenses.
The life of this world vanishes rapidly and changes suddenly. Therefore, beware of its sweetness so as to avoid the bitterness of its depriving, and beware of its delights so as to avoid the pains they lead to. Do not excessively build a life that Allah has decided is bound to destruction, and do not recline to (or like) it. Verily, Alláh has ordained on you that you should avoid its danger. Otherwise, you will expose yourselves to His Anger and justifiably earn His Punishment.”
[Book: Selected Friday Sermons, Dar-us-Salaam Publications]