I find this as a UX problem.
This problem happens to me when I leave a portal open for hours, the session expires and I have to log in again.
What happens is that before login in again I open a modal, like select file. In this moment is when the portal login form appears inside the modal. Then, when the log in action is completed the portal is loaded inside the modal. This is very weird.
The solution for this should be a complete logout when the session expires and also make sure that if a modal is presented for login, the portal is never loaded inside the modal.