Proper handle of login and logout