Limit Gutenberg blocks available to users to choose from

In the functions.php file I added

add_filter( 'allowed_block_types_all', 'func_allowed_block_types' );
function func_allowed_block_types( $allowed_blocks ) {
 
    return array(
        'core/embed'
    );
}

Then in my plugin I added this JS to the javascript file to enable only the embed blocks I wanted (Twitter, youTube and Vimeo)

wp.domReady( function() {
    const allowedEmbedBlocks = [
        'twitter','youtube', 'vimeo'
    ];

    wp.blocks.getBlockType( 'core/embed' ).variations.forEach( function( blockVariation ) {
        if (
            allowedEmbedBlocks.indexOf( blockVariation.name ) === -1
        ) {
            wp.blocks.unregisterBlockVariation( 'core/embed', blockVariation.name );
        }
    } );
} );