Islam teaches that a good dream is from Allah and a bad dream is from Satan. The Prophet ﷺ said the good dream of a believer is one of forty-six parts of prophethood, and that after a bad dream you should seek refuge in Allah from its harm.
From the Quran
إِذْ قَالَ يُوسُفُ لِأَبِيهِ يَـٰٓأَبَتِ إِنِّى رَأَيْتُ أَحَدَ عَشَرَ كَوْكَبًا وَٱلشَّمْسَ وَٱلْقَمَرَ رَأَيْتُهُمْ لِى سَـٰجِدِينَ ﴿4﴾
قَالَ يَـٰبُنَىَّ لَا تَقْصُصْ رُءْيَاكَ عَلَىٰٓ إِخْوَتِكَ فَيَكِيدُوا۟ لَكَ كَيْدًا ۖ إِنَّ ٱلشَّيْطَـٰنَ لِلْإِنسَـٰنِ عَدُوٌّ مُّبِينٌ ﴿5﴾
4[Of these stories mention] when Joseph said to his father,[584] "O my father, indeed I have seen [in a dream] eleven stars and the sun and the moon; I saw them prostrating to me." 5He said, "O my son, do not relate your vision to your brothers or they will contrive against you a plan. Indeed Satan, to man, is a manifest enemy.
Yusuf 12:4-5وَقَالَ ٱلْمَلِكُ إِنِّىٓ أَرَىٰ سَبْعَ بَقَرَٰتٍ سِمَانٍ يَأْكُلُهُنَّ سَبْعٌ عِجَافٌ وَسَبْعَ سُنۢبُلَـٰتٍ خُضْرٍ وَأُخَرَ يَابِسَـٰتٍ ۖ يَـٰٓأَيُّهَا ٱلْمَلَأُ أَفْتُونِى فِى رُءْيَـٰىَ إِن كُنتُمْ لِلرُّءْيَا تَعْبُرُونَ ﴿43﴾
And [subsequently] the king said, "Indeed, I have seen [in a dream] seven fat cows being eaten by seven [that were] lean, and seven green spikes [of grain] and others [that were] dry. O eminent ones, explain to me my vision, if you should interpret visions."
Yusuf 12:43وَرَفَعَ أَبَوَيْهِ عَلَى ٱلْعَرْشِ وَخَرُّوا۟ لَهُۥ سُجَّدًا ۖ وَقَالَ يَـٰٓأَبَتِ هَـٰذَا تَأْوِيلُ رُءْيَـٰىَ مِن قَبْلُ قَدْ جَعَلَهَا رَبِّى حَقًّا ۖ وَقَدْ أَحْسَنَ بِىٓ إِذْ أَخْرَجَنِى مِنَ ٱلسِّجْنِ وَجَآءَ بِكُم مِّنَ ٱلْبَدْوِ مِنۢ بَعْدِ أَن نَّزَغَ ٱلشَّيْطَـٰنُ بَيْنِى وَبَيْنَ إِخْوَتِىٓ ۚ إِنَّ رَبِّى لَطِيفٌ لِّمَا يَشَآءُ ۚ إِنَّهُۥ هُوَ ٱلْعَلِيمُ ٱلْحَكِيمُ ﴿100﴾
And he raised his parents upon the throne, and they bowed to him in prostration.[618] And he said, "O my father, this is the explanation of my vision of before. My Lord has made it reality. And He was certainly good to me when He took me out of prison and brought you [here] from bedouin life after Satan had induced [estrangement] between me and my brothers. Indeed, my Lord is Subtle[619] in what He wills. Indeed, it is He who is the Knowing, the Wise.
Yusuf 12:100فَلَمَّا بَلَغَ مَعَهُ ٱلسَّعْىَ قَالَ يَـٰبُنَىَّ إِنِّىٓ أَرَىٰ فِى ٱلْمَنَامِ أَنِّىٓ أَذْبَحُكَ فَٱنظُرْ مَاذَا تَرَىٰ ۚ قَالَ يَـٰٓأَبَتِ ٱفْعَلْ مَا تُؤْمَرُ ۖ سَتَجِدُنِىٓ إِن شَآءَ ٱللَّهُ مِنَ ٱلصَّـٰبِرِينَ ﴿102﴾
And when he reached with him [the age of] exertion,[1296] he said, "O my son, indeed I have seen in a dream that I [must] sacrifice you, so see what you think." He said, "O my father, do as you are commanded. You will find me, if Allāh wills, of the steadfast."
As-Saffat 37:102لَّقَدْ صَدَقَ ٱللَّهُ رَسُولَهُ ٱلرُّءْيَا بِٱلْحَقِّ ۖ لَتَدْخُلُنَّ ٱلْمَسْجِدَ ٱلْحَرَامَ إِن شَآءَ ٱللَّهُ ءَامِنِينَ مُحَلِّقِينَ رُءُوسَكُمْ وَمُقَصِّرِينَ لَا تَخَافُونَ ۖ فَعَلِمَ مَا لَمْ تَعْلَمُوا۟ فَجَعَلَ مِن دُونِ ذَٰلِكَ فَتْحًا قَرِيبًا ﴿27﴾
Certainly has Allāh showed to His Messenger the vision [i.e., dream] in truth. You will surely enter al-Masjid al-Ḥarām, if Allāh wills, in safety, with your heads shaved and [hair] shortened,[1517] not fearing [anyone]. He knew what you did not know and has arranged before that a conquest near [at hand].
Al-Fath 48:27
From the hadith
Narrated Abu Qatada:The Prophet (ﷺ) said, "A true good dream is from Allah, and a bad dream is from Satan
Narrated Abu Qatada:The Prophet (ﷺ) said, "A good dream that comes true is from Allah, and a bad dream is from Satan, so if anyone of you sees a bad dream, he should seek refuge with Allah from Satan and should spit on the left, for the bad dream will not harm him
Narrated Anas bin Malik:Allah's Messenger (ﷺ) said, "A good dream (that comes true) of a righteous man is one of forty-six parts of prophetism
Narrated Abu Huraira:I heard the Prophet (ﷺ) saying, "Whoever sees me in a dream will see me in his wakefulness, and Satan cannot imitate me in shape." Abu `Abdullah said, "Ibn Seereen said, 'Only if he sees the Prophet (ﷺ) in his (real) shape
Narrated Abu Huraira:I heard Allah's Messenger (ﷺ) saying, "Nothing is left of the prophetism except Al-Mubashshirat." They asked, "What are Al-Mubashshirat?" He replied, "The true good dreams (that conveys glad tidings)
Quran: the Arabic Uthmani text from Tanzil.net (CC BY 3.0); English, Saheeh International, from QuranEnc.com.
Hadith: the English and the grades from the open hadith dataset (fawazahmed0/hadith-api), the same narrations MuslimGPT checks every quote against. Each one opens its own page with the Arabic.
The introduction is ours. For a ruling on your own situation, ask a scholar you trust.