-1
export const isLoginValid = async token => {
  try {
    let result = await axios.post(API_URL + "/verify", null, {
      headers: { Authorization: "Bearer " + token }
    });
    return await result.data;
  } catch (error) {
    console.log("Unable to verify");
    return false;
  }
};

I am using the code above to check if a user's login is valid. However, the return statement returns a Resolved Promise with the data inside the promise. Data needs to return true or false. Is there a way to unwrap the promise and just return the data? I'm fairly new to async/await. I've tried suggestions found in here but no matter what i try it returns a promise.

Edit

By the way, this is not a duplicate, the suggested answer is not what my problem was. I had trouble getting the value from a async/await call using axios since it kept returning a promise.

This helped me get the value from an async/await axios called.

Async/Await in Axios

nando
  • 337
  • 1
  • 5
  • 18

1 Answers1

0

Nope. You're calling an async request within this function, so the function will never be able to return the result of this async request synchronously. Wherever you're calling this function you'll need to use the resulting promise to handle the result.

ApplePearPerson
  • 4,209
  • 4
  • 21
  • 36