Add logout functionality and error checking in login and register