Wait for ajax before do login things

There were some weird errors around user logout and login, so I have put wait for ajax there to protect it.
Shouldn't there be one on the back of the click to log in?