Would it be as easy as just wrapping a bulk of the code in a !is_user_logged_in() ?
No, because the domain lookup happens long before WP can determine if you are logged in. WP has to determine what domain to retrieve the auth cookie from before retrieving said cookie.