DEV Community

Discussion on: Using Amplify CLI for adding Auth to your Hasura GraphQL engine

csatterlee profile image
csatterlee • Edited on

Thanks for the great tutorial. I managed to get this working easily, but I'm having a lot of trouble with the next step, which is connecting my newly authenticated app to Hasura via Apollo. The token I get works fine if I paste it into Hasura, but when I set up Apollo to send requests to Hasura I get the following error:

Error: GraphQL error: Malformed Authorization header

I don't know what the problem is or whether it's Hasura or Apollo or Cognito, but if I console log the jwt before passing it to Apollo I can paste it into Hasura and it works fine. Is there a step I'm missing? Here's my code, pretty much right out of the Apollo docs example:

async function getSession() {
let idToken = res.getIdToken()
let jwt = idToken.getJwtToken()
//You can print them to see the full objects
return jwt

const token = getSession()

const client = new ApolloClient({
uri: '',
headers: {
authorization: token ? Bearer ${token} : "",


//backtics don't show in headers section

vladimirnovick profile image
Vladimir Novick Author

getSession is async function and you missed await keyword calling getSession. Your token is a promise.