You require to recognize happiness sadness, pleasure-pain are temporary like seasons and you require to fix your mind on Ishvara and follow Dharma this teaching is repeated in Upanishads, Gita and by many Rishis.
We require to be equidisposed to both praise and criticism ,to desirable and undesirable.
Bhagavad Gita 12.17
Those who neither rejoice in mundane pleasures nor despair in worldly
sorrows, who neither lament for any loss nor hanker for any
gain, who renounce both good and evil deeds, such persons who are
full of devotion are very dear to Me.
Bhagavad Gita 12.18 - 12.19
Those, who are alike to friend and foe, equipoised in honor and
dishonor, cold and heat, joy and sorrow, and are free from all
unfavorable association; those who take praise and reproach alike,
who are given to silent contemplation, content with what comes their
way, without attachment to the place of residence, whose intellect is
firmly fixed in Me, and who are full of devotion to Me, such persons
are very dear to Me.