Allah gives opportunities to do righteous acts for the ones he wills good
the Messenger of Allah ﷺ said, "If Allah wills goodness for a servant, He sweetens him.” It was said, “What would be his sweetness?” The Prophet said, “Allah opens the door of righteous deeds for him before his death and then receives his soul in that state.”
قَالَ رَسُولُ اللهِ ﷺ «إِذَا أَرَادَ اللهُ بِعَبْدٍ خَيْرًا، عَسَلَهُ۔» قِيلَ: وَمَا عَسَلُهُ؟ قَالَ: «يَفْتَحُ اللهُ لَهُ عَمَلًا صَالِحًا قَبْلَ مَوْتِهِ ثُمَّ يَقْبِضُهُ عَلَيْهِ۔»