0

I am trying to call the GitHub GraphQL API using Clerk's GitHub authentication on Next.js. After the user logged in via GitHub (which works flawlessly), the API call to the GitHub GraphQL API is made. This is what the decoded Authorization header of that request looks like (I replaced non-relevant data with 'abc' for security reasons):

{
  "azp": "http://localhost:3000",
  "email": "{{user.email}}",
  "exp": abc,
  "github": {
    "access_token": "{{user.external_accounts.github.access_token}}"
  },
  "iat": abc,
  "iss": "abc",
  "jti": "abc",
  "name": "abc",
  "nbf": abc,
  "sub": "abc"
}

Seems like the variables aren't... getting recognised as variables?

This is the JWT template:

{
    "name": "{{user.first_name}} {{user.last_name}}",
    "email": "{{user.email}}",
    "github": {
        "access_token": "{{user.external_accounts.github.access_token}}"
    }
}

And this is the relevant part of the code:

const query = `
          query {
            viewer {
              repositories(first: 100, ownerAffiliations: OWNER, isFork: false) {
                nodes {
                  name
                  description
                  stargazerCount
                  url
                }
              }
            }
          }
        `;
    
          
        const response = await fetch("https://api.github.com/graphql", {
          method: "POST",
          headers: {
            Authorization: `Bearer ${token}`,
            "Content-Type": "application/json",
          },
          body: JSON.stringify({ query }),
        });

I've been trying around for days now, reading through Clerk & GitHub docs, tried around with variable names and double-checked everything but can't seem to find a solution. Did someone already encouter similar issues or even knows a solution to this? Thank you so much!

1
  • Is the GQL query or fetching the access token that isn't working? How does the JWT template get the variables? Could you share the result of the GQL query and how you're setting up the auth headers/JWT? I'd imagine there is some code that inserts the fields Commented Jan 22 at 22:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.