How to fix GraphQL error – Not Authorized

How to fix GraphQL error – Not Authorized


2

I keep geting this error:

Error: GraphQL error: Not Authorized!

Code is:

const queries = gql`
  query {
    mystreak
  }
`;

  render() {
    return (
      <Query query={queries}>
        {({ loading, error, data }) => {
          console.log(loading);
          console.log(error);
          console.log(data.mystreak);
        }}
      </Query>
)
}

App is built in React.js, and I am pretty new to GraphQL.

Also data is undefined.

Any ideas?

Thanks in advance

7 Answers
7


3

I’m guessing you use Apollo.
We are lacking a lot of information, especially regarding your backend, but it looks like you are missing an Authorization header in your http requests:

https://www.apollographql.com/docs/link/links/http.html#options

const link = createHttpLink({
    uri: "/graphql",
    headers: {
        Authorization: 'Bearer <your token here>'
    }
});

Check the documentation of your backend for the token value.


2

I solved this issue by removing eas: projectId from app.json:

"extra": {
  "eas": {
    "projectId": "a1b2c3d4-e5f6-g7h8i9-j1k2-l3m4n5o6p7"
  }
}

I need a build for development, the company’s Expo project ID is different than my account’s project ID, thus the problem…


0

Im not a techie and I never mess with codes and don’t even know where they are. I have not changed anything and when I try to use FaceBook today I can not use Messenger it gives me this error message. I have no idea. I see the codes above but do not believe normal users would pay tech to fix something that they probably fixed to generate more income BOO HISS

New contributor

Linda Ballard is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


-1

Me too. Must be an issue in FB messenger.

New contributor

user22784624 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1


-2

Me too. Just started about 45 minutes ago.

New contributor

user22784600 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1


-2

I just started getting it too on FB messenger. what the heck is going on?

New contributor

Debbie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1


-2

I just got the same error message in FB messenger a few minutes ago.

New contributor

Michele is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

Leave a Reply

Your email address will not be published. Required fields are marked *