Improve auth error handling and state machine