title: WP Custom REST Route - Wordpress wp_rest Nonce seems to have no influence
body: <p>So I am setting up an AJAX call in Wordpress on the front-end and I came across the <code>wp_create_nonce('wp_rest')</code>. I read some stuff about it but I can't manage to understand the use of it since I can simply not use it and it still works perfectly fine. Can anyone explain me how it works and maybe tell me if I am doing something wrong?
  Also in the end I'd like to have my custom REST route to only be accessable by my system and not by calling the REST URL manually and also by guests and logged in users. But afaik that's what the Nonces are for?</p>
  <p>My PHP Code:</p>
  <pre><code>add_action('wp_enqueue_scripts', 'enqueue_scripts');
  function enqueue_scripts(){
      wp_enqueue_script( 'ajax-script', plugins_url( 'custom.js', __FILE__ ), array('jquery'), false, true );
      
      // in JavaScript, object properties are accessed as ajax_object.ajax_url
      wp_localize_script( 'ajax-script', 'ajax_object', array( 
          'restURL'  =&gt; rest_url(),
          'restNonce' =&gt; wp_create_nonce('wp_rest')
      ));
  }
  
  add_action('rest_api_init', function(){
      register_rest_route('wc/v3/', '/updateCartData/', array(
      'methods' =&gt; 'GET',
      'callback' =&gt; 'restAPI_updateData_callback'
      ));
  });
  
  function restAPI_updateData_callback(){ 
      $response = array();
      
      array_push($response, $_GET['test_data']);
      
      echo json_encode($response);
      
      // Genutzt um die Kontrolle zurück an den AJAX Call zu geben (notwendig?)
      // Siehe: https://anhkarppinen.com/die-and-wp-die-wordpress/
      die;
  }
  </code></pre>
  <p>My JS/AJAX Code:</p>
  <pre><code>function updateData(){
      $.ajax({
          type: 'GET',
          url: ajax_object.restURL + 'wc/v3/updateCartData',
          beforeSend: function(xhr){
              xhr.setRequestHeader('X-WP-Nonce', ajax_object.restNonce);
          },
          data: {
              'test_data': 'test'
          },
          success: function (response) {
              if(response){
                  alert(response);
              }
          },
          permission_callback: '__return_true'
      });
  }
  </code></pre>
  <p>The JS Method is called like this within the Cart of Woocommerce:</p>
  <pre><code>&lt;input id=&quot;user&quot; type=&quot;number&quot; step=&quot;1&quot; min=&quot;1&quot; max=&quot;5&quot; value=&quot;1&quot; title=&quot;Benutzeranzahl&quot; size=&quot;4&quot; placeholder=&quot;1&quot; inputmode=&quot;numeric&quot; autocomplete=&quot;off&quot; onchange=&quot;updateData()&quot;&gt;
  </code></pre>