Ali had stayed behind from the Prophet ﷺ at Khaybar because he was suffering from an eye ailment. Then he said, "Am I to stay behind from the Messenger of Allah ﷺ?" So Ali set out and caught up with the Prophet ﷺ.On the eve of the night before the morning Allah granted the conquest, the Messenger of Allah ﷺ said, "Tomorrow I shall surely give the banner," or he said, "the banner shall surely be taken by a man whom Allah and His Messenger love," or he said, "who loves Allah and His Messenger. Allah will grant him victory."Suddenly we saw Ali, though we had not expected him. The people said, "Here is Ali." So the Messenger of Allah ﷺ gave it to him, and Allah granted him the victory.
كان علي قد تخلف عن النبي ﷺ في خيبر، وكان به رمد، فقال: أنا أتخلف عن رسول الله ﷺ، فخرج علي فلحق بالنبي ﷺ، فلما كان مساء الليلة التي فتحها الله في صباحها، قال رسول الله ﷺ: لأعطين الراية- أو ليأخذن الراية- غدا رجلا يحبه الله ورسوله، أو قال: يحب الله ورسوله، يفتح الله عليه. فإذا نحن بعلي، وما نرجوه، فقالوا: هذا علي، فأعطاه رسول الله ﷺ، ففتح الله عليه.
Bukhari narrated it in the Virtues of the Companions (3702) and in the Military Expeditions (4209), and Muslim in the Virtues of the Companions (2407), both through Hatim bin Ismail, from Yazid bin Abu Ubayd, from Salama bin Akwa, who said, and then he mentioned it.