Try to solve some issues around login.

There were some weird errors around user logout and login, so I have put wait for ajax there to protect it.