Ali remained behind the Prophet ﷺ during the battle of Khaibar as he way suffering from some eye trouble but then he said, "How should I stay behind Messenger of Allah ﷺ?" So, he set out till he joined the Prophet. On the eve of the day of the conquest of Khaibar, Messenger of Allah ﷺ said, "(No doubt) I will give the flag or, tomorrow, a man whom Allah and His Apostle love or who loves Allah and His apostle will take the flag. Allah will bestow victory upon him." Suddenly 'Ali joined us though we were not expecting him. The people said, "Here is 'Ali. "So, Messenger of Allah ﷺ gave the flag to him and Allah bestowed victory upon him. (Using translation from Bukhārī 2975)
عَنِ النَّبِيِّ ﷺ بِخَيْبَرَ وَكَانَ رَمِدًا فَقَالَ أَنَا أَتَخَلَّفُ عَنْ رَسُولِ اللهِ ﷺ؟ فَخَرَجَ فَلَحِقَ بِالنَّبِيِّ ﷺ فَلَمَّا كَانَ مَسَاءُ اللَّيْلَةِ الَّتِي فَتَحَ اللهُ فِي صَبَاحِهَا قَالَ رَسُولُ اللهِ ﷺ لَأُعْطِيَنَّ الرَّايَةَ أَوْ لَيَأْخُذَنَّ الرَّايَةَ غَدًا رَجُلٌ يُحِبُّهُ اللهُ وَرَسُولُهُ أَوْ قَالَ يُحِبُّ اللهَ وَرَسُولَهُ يَفْتَحُ اللهُ عَلَيْهِ فَإِذَا نَحْنُ بِعَلِيٍّ ؓ وَمَا نَرْجُوهُ فَقَالُوا هَذَا عَلِيٌّ فَأَعْطَاهُ رَسُولُ اللهِ ﷺ الرَّايَةَ فَفَتَحَهَا اللهُ عَلَيْهِ