Problem in setar performance token

Asked

Viewed 70 times

-1

I’m having trouble authenticating my application, I do the process of inserting a token jwt to the user login, but I can’t make the application read the token or I’m losing you at some point, Repo link on github and I will indicate where the authentication function is (which I use as middleware)

The authentication function is in api/src/graphql/middleware/auth.js

for those who want to run the application, I’m using bank postgre, and you will need to create a file .env with the configuration:

PG_USERNAME=postgres
PG_PASSWORD=YOUR_PASSWORD
PG_DATABASE=postgres
PG_PORT=5432
PG_HOST=localhost
API_SECRET=YOUR_API_SECRET

1 answer

0


You need to pass the localStorage token in the Relay Environment

  return fetch("http://localhost:5000/graphql", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      ++"Authorization": "Bearer" + localStorage.getItem("jwtToken")
    },
    body: JSON.stringify({
      query: operation.text,
      variables
    })
  }).then(response => {
    return response.json();
  });
}```

Browser other questions tagged

You are not signed in. Login or sign up in order to post.