So like me, if anyone using this plugin just to only allow authenticated users, and want access to the rest api, you can use this script I have just created.
Add it to your functions.php in the theme root.
add_action('init','srs_restrict_public_access');
function srs_restrict_public_access(){
global $wp;
if ( !in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) ) && !empty( $wp->query_vars['rest_route'] )){
if(!is_user_logged_in()){
$current_path = empty( $_SERVER['REQUEST_URI'] ) ? home_url() : $_SERVER['REQUEST_URI'];
$redirect_url = wp_login_url( $current_path );
wp_redirect( $redirect_url, '302' );
}
}
}