Fix bug in login and logout