title: How to get current logged in user using Wordpress Rest Api?
body: <p>I tried to add a custom request.</p>
  
  <pre><code>add_action('rest_api_init', function () {
      register_rest_route( 'custom', '/login', array(
          'methods' =&gt; 'GET',
          'callback' =&gt; function(WP_REST_Request $request) {
              return wp_get_current_user();
          }
      ));
  });
  </code></pre>
  
  <p>But it always returns a user with with ID = 0;
  I also tried this:</p>
  
  <pre><code>add_action('rest_api_init', function () {
      register_rest_route( 'custom', '/login', array(
          'methods' =&gt; 'GET',
          'callback' =&gt; function(WP_REST_Request $request) {
              return is_user_logged_in();
          }
      ));
  });
  </code></pre>
  
  <p>And it always returns false.
  But the user is logged in for sure.</p>
  
  <p>I added my custom login</p>
  
  <pre><code>add_action('rest_api_init', function () {
      register_rest_route( 'custom', '/login', array(
          'methods' =&gt; 'POST',
          'callback' =&gt; function(WP_REST_Request $request) {
              $nonce = wp_create_nonce("wp_rest");
              $user = wp_signon(array('user_login' =&gt; $_POST['username'],
                  'user_password' =&gt; $_POST['password'], "rememberme" =&gt; true), false);
              if (is_wp_error($user)) {
                  return $user;
              }
  
              //do_action( 'wp_login', "capad" );
              //$user['isloggedin'] = is_user_logged_in();
              return array('user' =&gt; $user,
                  'nonce' =&gt; $nonce);
          }
      ));
  });
  </code></pre>
  
  <p>And I add "X-WP-Nonce" in as a header for http request</p>
  
  <p>And now every request outputs: <code>{"code":"rest_cookie_invalid_nonce","message":"Cookie nonce is invalid","data":{"status":403}}</code></p>