Nonce header stopped working wordpress post rest api

0

I had a working post route with nonce header in wordpress using npm. Now it only works if I comment out the nonce header. With nonce header, console returns message “(routename) not defined”. Route is recognized with nonce and WP_REST_SERVER::READABLE method, but not with POST method.

JS side:

    var updateLikes = new XMLHttpRequest(); 

    updateLikes.setRequestHeader('X-WP-Nonce', SB.nonce);

php side:

    add_action('rest_api_init', 'sbLikeRoutes');

    function sbLikeRoutes(){
       register_rest_route('SB/v1', 'manageLike' , array(
       // 'methods' => WP_REST_SERVER::READABLE,
       'methods' => 'POST',
       'callback' => 'SBPostLike'
     ));
    }

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer