A city was built in a location that's generally difficult to access (floating in the sky, on a remote island, on top of a mountain or something similar). The primary way of accessing it is by teleporting inside. In this world, skilled mages can teleport from anywhere, but only to a previously built "portal", in a similar way fast travel points work in video games. Small objects, such as food crates, can also be teleported to a "portal".
This city contains one such "portal" for all arrivals which functions in a way similar to real-world airports, with heavy security, customs checks etc. A "portal" can also be temporarily closed, which prevents anyone from arriving until it's reopened.
This makes any large-scale invasion impossible, but a devastating smaller scale attack still seems feasible: a group of enemy mages could coordinate to have everyone teleport at the same time and overwhelm the guards stationed near the "portal" before they have a chance to close it, then proceed to steal valuable artifacts / assassin a target / wreck havoc in some other way.
What mechanism (magical or otherwise) could effectively prevent this from happening?
My ideas so far were:
Have teleportation require some sort of "key" (analogous to real-world entry visas) that needs to be in possession to make teleporting to this city possible. However, enemy mages could, over time, steal a sufficient number of these and invade. Or, if this "key" is somehow tied to a person (e.g. in their blood), it wouldn't stop a group of former allies who had a change of heart.
Move this "portal" outside the city walls. While this makes a direct attack more difficult, it makes it easy for enemy forces to create a blockade and starve the city of vital resources that would come via this only entrance.
Edit: Just to clarify, the idea is not to make the city completely impervious to attacks of any kind, my main goal is to make use of this teleportation mechanic without worrying it introduces new types of attack that wouldn't otherwise exist. Things like infiltrations and insurgencies are still a very real threat.
Edit2: I see a few answers suggest changing the teleportation mechanic in some way. I'm generally open to that (e.g. adding a delay, requiring more elaborate conditions to be met etc), but one thing I don't want to change is the fact you can teleport from anywhere, as the original reason for introducing this mechanic was for the main characters to be able to access the city without having to explain how they managed to get back.
Regarding enemies building their own second "portal" after infiltrating the city: the assumption is that such a venture is possible, but extremely costly in terms of both materials and time and relatively easy to detect.