The Companions used to say, “AsSalaamualayka ayuhan Nabi (when the prophet was alive)” and “AsSalaamualayka ‘Alan Nabi (after Prophet (e) passed away).”
Both are correct. As there is a narration in Muwatta of Imam Malik, which is authentic, that Umar bin Khattab (radhiallaahu anhu) used to teach the people to say, “AsSalaamualayka ayuhan Nabi” in the sermon after the Prophet’s (e) death.
[Taken from the lessons on “Conditions, Pillars and Obligation of Salah – Shaykh ul Islaam Muhammad bin Abdil Wahhab رحمه الله Explanation by Shaykh Abdul Muhsin al abbaad حفظه الله Taught by: Abdulilah Lahmami]