Abu Zarr narrates that the Holy Prophet (s.a.w.s.) said: I and Ali have been created from one Light and we were glorifying Allah on the right side of the Arsh two thousand years before the creation of Adam. When Allah created Adam, He put this Light in his loins. When he was allowed to dwell in Paradise we were in his loins. Likewise when Nuh was riding the ship we were in his loins. So also when Ibrahim was thrown into fire. Allah transferred us from holy loins into holy wombs until we reached the loins of Abdul Muttalib. Allah divided the Light into two parts, placed me in the loins of Abdullah and Ali in the lions of Abu Talib. He granted me prophethood and gave eloquence and courage to Ali and gave derivatives from His holy names to both of us. Allah is the Lord of the Throne (Arsh) He is Mahmud and I am Muhammad. Allah is High (Aalaa) and my brother is Ali. He designated me for messengership and prophethood and appointed Ali for guardianship and Imamate and to command people with truth.
Hayaat al-Quloob v 2 chap 1