0

This is my JS code for the API

export const getUser = async (user) => {
    //Working
    const json = await fetch( "*****/username/getUser", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        user:user
      }),
    })
      .then((res) => {
        return res.json();
      })
      .catch((err) => {
        console.log("Error in getUser: " + err);
      });
    return json;
  };

Here is an attempt to make the request, which unfortunately return the authentication error.

    fetchUser.request("kirolosM")
    .then((result)=>{  
        console.log(result);
    }).catch((err)=>{console.log("Error ",err);})

The error

{
  "message": "Missing Authentication Token"
}

I have tested the API using postman and it is working as expexted.

Can Arda Aydin
  • 204
  • 2
  • 13

1 Answers1

0

Probably useful to compare the request sent from your json code to the one you're sending from postman. It looks like you need to include you auth token in your headers in your request.

Something like

export const getUser = async (user) => {
    //Working
    const json = await fetch( "*****/username/getUser", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "Authentication": `Bearer ${token}`
      },
      ...
Alex
  • 152
  • 6