Home Support Themes TaskHive Get Logged in User data through an API.

Get Logged in User data through an API.

  • Author
    Posts
  • m.ali.rashid

    Hey Team
    I have created a new page and integrated it with ReactJS. I want to call a REST API endpoint using fetch() where I can get the currently logged-in user.
    This is my code so far.

    async function loadUserData() {
          const response = await fetch( "http://beyondsport.co/wp-json/hivepress/" );
          if (!response.ok) { return; }
          const data= await response.json();
          console.log(data);
        }

    As You can see, I need an API end-point to get logged-in user data.
    Thanks.

    ihor developer

    Hi,

    Please try using the official WordPress REST API for fetching users https://developer.wordpress.org/rest-api/reference/users/

    m.ali.rashid

    Thanks. But I need to know which user is logged in. Similar to wp_get_current_user(). But using RestAPI.

    m.ali.rashid

    Thanks @ihor
    This is the rest-api end-point I’m using
    https://beyondsport.co/wp-json/wp/v2/users/me

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.