Refactor logic for logout and auth failures