Answered by Sayyidi Habib Umar bin Hafiz (may Allah protect him and benefit us by him)
As soon as you wake up, you should spit on your left side (without any spittle coming out) three times and seek refuge in Allah from any evil you have seen. You should not inform anyone about what you have seen. Then no harm will come to you.
Recite before sleeping: Ayat al-Kursi once and Surat al-Ikhlas, al-Falaq and al-Nas three times each as well as some prayers upon the Prophet ﷺ. This will be a protection from bad dreams.