Let’s lead our lives in a way that Allah gives us also a good death.
It is all part of the greater plan of Allah Subhanahu Wa Ta’ala, that certain things He does not give you a choice about. Those things, Allah Almighty has decided for reasons known to Him.
One of the factors that Allah has kept is a very interesting, beautiful teaching that your final judgment depends on how your life ends.
The Prophet, peace be upon him, used to make a du’a,
اللهم إني أسألك حسن الخاتمة
Allahumma inni as aluka husnal khatimah: O Allah, I ask You for a good end to my life.
Because there is a hadith that states that a person who does a lot of good for so many years and suddenly messes up at the end, they’ve lost. And the person who’s done a lot of bad through his life, but suddenly made everything right at the end.
They’ve gained a person who was a disbeliever, and suddenly they became a Muslim. They believed in Allah and submitted just before they passed on.
They died as submitters. Good news to them. Islam deletes the bad that was done before it. The same applies to tawba and repentance. Whatever was before it is deleted.
A gift of Allah is that we are not judged by our sins. We are judged by our repentance.