How to restrict an entire WordPress site to visitors, but the register and login page?

Below code will work with WordPress default login/register screens:

add_action( 'wp', 'member_only_site' );
function member_only_site( ) {
    if ( ! is_user_logged_in( ) ) {
          auth_redirect();
    }
}