If you have a medium-term successful Napoleonic Empire, you could then get an ongoing co-ordinated Iberian resistance, that feels they are all brothers against the evil French. Added in to the fact Portugal has already been divided up into tiny republics, a single People's Iberia could come out of it when Napoleon eventually dies and his empire collapses.
Well, the feeling of iberian brotherhood has been there in larger or shorter measure since the Middle Ages and it has not led to an urge for an union. Well, the common struggle against the muslims, or better said, the ideological construct of a common struggle, led to the first paniberian project, but it ended as all we know. Obviously, a common struggle against the french could strenght those feelings, specially in the age of Romanticism, but also that same age of Romanticism, as Miguel noted, and the particular and somewaht exceptional political developments at the time in Spain and Portugal would complicate things. Even inside OTL Spain, the idea of a brotherhood amongst the iberian peoples is not incompatible with separatist feelings, go figure.
To make things even more difficult, during the french invasion of Iberia the ideological fractures coexist with a more subtile fracture about the construction of the state - "from above" or "from below"- conflating with a more doctrinary Liberalism and inter-elites interests. It was already conflictive inside the Spanish Monarchy to keep in order all the local and regional "Juntas" even in the penisular territories (plus the colonial unrest making it even more problematic in the Americas), which after all were the spine of the uprising against Bonaparte fromt the POW of the sovereignity, that adding the portuguese question could be mindblowing.
By their part, the portuguese have their court in Brazil, what will lead to its own political inner struggle, but driven by very particular interests that I'm not sure wether are compatible with an iberian union.
Finally we have the spanish national conscience taking form precissely during the Peninsular War. Perhaps it wouldn't be difficult to insert the consideration of Portugal as part of the spanish nation in the proccess. But, on the opposite sense, the portuguese identity is already formed and the surging romantic national cosncience, as noted by Miguel, is somewaht defined as "we-are-not-spaniards". That's more difficult to change, beceause has deeper roots, predating nationalisms. That's why in noted that Iberism found more acceptation latter in more "leftist" developments of liberalism and then in revolutionnary movements derived from these.
In the spanish side the procces led to the promaclation of the Constitution of 1812, but in the road to reach it we have an angry absolutist opposition, conflicts amongst the "Junta Central" and the regional and local juntas, which are exacerbated in the colonies. At this point in 1812, some american territories have broken de facto with Madrid (or rather Cadiz), some even proclaiming their own constitutions before (Venezuela 1811) and others pushing for both a more proportional representation and a more decentralized approach to the new constitution or for a separation of kingdoms under the same Monarchy.
On the portuguese side, with the king still acting as a king, things are a bit less complicated what probably make their procces slower. But the problem is that, after all, the king is on the other side of the ocean. So, what is now the place of metropolitan Portugal in the Empire. Are we now a colony of Brazil? add to this the loss of the colonial comercial monopoly and the loss of influence in the imperial decissionmaking, and you have large support to the constitutional proccess of 1820, though different political and social sectors have different ideological approachs to what have to be the new constitution and its limits.
So, we have a Spain with one of its typical problems of identity, but a very serious one, with the colonies breaking and a lot of problems around the internal organization and even the implications of the idea of nation and the articulation of people's severeignity. Meanwhile Portugal is looking with
saudade upon the ocean towards Brazil making heartbreaking songs about their times of love with the king in the bohemian nights of Lisbon and worried about the future implications of the new situation if the king doesn't come back once the french are beaten (as actually happened in OTL). In other words, while the fight is common and similar, while one part is primarily looking inside herself at the point it's neglecting the colonial problems and demands, the other is looking outside, because the different results of the invasion regarding their monarchs (neutralization and relocation respectivelly) have created different problematics, difficult to conciliate.
Cheers.