I've finally decided to make a single topic for both modern territories as they share a lot of common history, except the Northern part of Morocco. They were just separed by European colonization.
During the 1st millenium B.C., Western Sahara and Southern Morocco were peopled by Berber nomads. In the same time, Phoenicians and their Carthage descendants settled in the Northern Morocco. Some people think they tried to land on Western Sahara but there is nothing to prove these statements. Northern Morocco became a Roman vessel as the allied kingdom of Mauretania Tingitania, which betrayed their former Numidian masters under the King Bocchus (son-in-law of the Numidian King Jugurtha). They're finally betrayed and annexed by Rome after the King Ptolemy (son of Cleopatra Selene II, daughter of Mark Antony & Queen Cleopatra) assassination in Lugdunum (modern Lyon, France) and the Aedemon War which followed.
Vandals invaded the remains of the Mauretanian territory in 429, retaken approx. a century later by Byzantines. This territory became part of the Umayyad Caliphate in the beginning of the 8th century, under the rule of Syrians followed by the Spanish Umayyads after the Syrian Umayyads fell. Some small kingdoms or Emirates emerged. During all this time Berbers remained isolated in the actual Western Sahara and Southern Morocco, and finally invaded in mid-11th century the Northern part and the Arabic Spain as the future Almoravid Caliphate.
In mid-12th century, another Berber people took the power under the name of Almohads and founded a new Caliphate, which falled one century later and became the Marinid Sultanate. 1st European settlements started with Italian, Portuguese and Spanish explorers. In 1472 Marinids were defeated by the Wattasids, another Berber people. During that time, some coastal territories were mainly under the control of Portugal (including Ceuta in those times, but excluding a few territories in the Mediterranean coast which were Spanish like Melilla). Western Sahara and Southern Morocco remained as a vessel emirate which became independant under the Saadi dynasty and finally invaded Northern Morocco and all European settlements in Western Sahara. Moriscos were expelled from Spain and landed in Rabat & Salé in Morocco, to become a pirate state: the Republic of Salé. This territory is taken back by the future rulers of the whole country.
After the Saadi Empire disrupted, a new dynasty unified the country: the Alaouites, and founded a sultanate, which is equivalent to the Sharifian Empire. After 1 century, they finally removed all Portuguese settlements (and the British colony of Tangier, gave as a dot a few centuries earlier). Sulayman I started an isolationnist policy. His successor started to be victim of the European colonization, defeated by the French (as allies of Abdelkader El Djezairi, Algerian emir before French invasion) and the Spanish after border incidents in Ceuta (which became Spanish after a Portugal-Spain conflict earlier). They finally took possession of Ifni as a war compensation, before taking full control of Western Sahara (in order to block British settlements of Donald MacKenzie) as Spanish Sahara.
Because of loans from France, the sultan started to lose control of his ports and finally. France took control of the country, but with troubles in the beginning due to Germans, revendicating Morocco as well. In 1912 Morocco became officially a French protectorate, and France gave Spain a secondary protectorate in Northern Morocco. Please note that Franco was leading the colonial troops of Morocco when started the Civil War in Spain in 1936. Tangier became an international zone in 1923, with lots of French, British, Spanish and Italian interests. France definitely defeated local rebels in 1934. Please note that Germany gave weapons to the rebels, mainly during WWI through the Spanish part. During WWII, the sultan, which was more like a vessel during the protectorate, decided to resist versus the commands from the Vichy regime and started to join the Free French. Notice that the French protectorate was freed in 1942. This liberation gave locals the idea to become independant more strongly than before, making the sultan leaving to an exile.
In 1956 Morocco became independant, reunifying the Spanish Morocco and the French protectorate in an independant kingdom, under the rule of Mohammed V, former sultan before his exile, and tried to enlarge the country to its old possessions (Greater Morocco, as an equivalent of the precolonial Sharifian Empire), including Western Sahara, Western part of Algeria and Mauritania. In 1957 Morocco and his Sahrawi mercenaries was defeated in Ifni by Spanish and French troops. In 1961 Mohammed V died, replaced by his son Hassan II. In 1963, the newly-independant Algerian border was invaded by Morocco, leading to the Sand War. Finally Morocco abandoned his Western Algerian revendications after a OAU (predecessor of the African Union) mediation. In 1967 Morocco finally recognized Mauritania as independant, leading Morocco to abandon all their claims except Spanish Sahara. In 1969 Ifni is left to Morocco by Spain. An International Court gave an advice about the future of Spanish Sahara, saying this territory should more be subject to a referendum to determine its new status. Finally after the Green March, initiated by the King himself, Spain decided to share in 1975 the territory with Morocco and Mauritania, leaving the territory in 1976.
In the same time, the Polisario Front, Sahrawi movement fighting for the independance, founded the Sahrawi Arab Democratic Republic when Spain definitely left the territory. Since then Polisario started to fight the new rulers. Polisario, with Algerian support, started to fight Mauritanian troops, considered weaker than Moroccan troops. After the Mauritanian putsch in 1978, the new Mauritanian regime abandoned his claims to SADR, but Morocco decided to annex the Mauritanian part too. Finally, in 1980, the front was definitely stabilized with Morocco taking control of 80% of the Western Sahara and building a separation wall with SADR. Hassan II died in 1999, and his son Mohammed VI took the power.
Notice that SADR minted coins but finally never introduced them in common circulation, moving to the Algerian Dinar as a circulating currency. But the Sahrawi currency still exists de jure in SADR, at par with the former Spanish Peseta (now using the euro-peseta conversion rate: EUR 1 = EHP 166.386). In Morocco and Morocco-owned part of Western Sahara is used the Moroccan Dinar.
Morocco 19th-21st centuries (modern coinage since 1882) currency rates:
1 rial = 10 dirham = 50 mazunas (new currency system, 1882)
1 rial = 5 pesetas (Spanish Morocco, 1912)
1 rial = 10 francs (French Morocco, 1921)
1 peseta = 10 francs (Morocco reunification, 1957)
1 dirham = 100 francs (1960)
1 franc = 1 santim (1974)
Numidian coinage:
https://en.numista.com/catalogue/numidie-1.html
Byzantine Empire coinage:
https://en.numista.com/catalogue/byzance-1.html
Umayyad Caliphates coinages:
https://en.numista.com/catalogue/islamic-caliphates-8.html#devise3088
https://en.numista.com/catalogue/islamic-caliphates-8.html#devise3086
Almoravid Caliphate coinage:
https://en.numista.com/catalogue/islamic-caliphates-8.html#devise2908
Almohad Caliphate coinage:
https://en.numista.com/catalogue/islamic-caliphates-9.html#devise2934
Moroccan coinage:
https://en.numista.com/catalogue/maroc-1.html
Western Sahara coinage:
https://en.numista.com/catalogue/sahara_occidental-1.html