Steadfastness comes through firm belief, guarding the daily prayers, keeping righteous company even if only online, continual learning, and turning to Allah for constancy. The Prophet ﷺ frequently asked Allah to keep his heart firm upon the faith.
References
Jami at-Tirmidhi 3522
Informational, not a personal fatwa. Consult a qualified scholar for rulings on your situation.