[Vuejs]-Retrieve wordpress user meta using rest API using vue

0👍

You can’t get user information because 2 requests are running concurrently. Haven’t got the token, the get user meta request has already run, so now token = ''

To fix this you should add await before the login request.

At this time, the request get user meta will wait for the login request to finish running

async mounted(){

    let token = "";
    await axios.post('https://example.com/wp-json/jwt-auth/v1/token', {
      username: 'USERNAME',
      password: 'PASSWORD',
    }).then((res) => {
      token = res.data.token;
    });

    axios.get('https://example.com/wp-json/wp/v2/users/me', {
      headers: {
        Authorization: `Bearer ${token}`,
      },
    }).then((res) => {console.log(res.data)});
  }

Leave a comment