hasura / react-apollo-todo

A todo app with react, apollo demonstrating graphql queries, mutations and subscriptions.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Authorization Header gives error

tspanu opened this issue · comments

The current implementation of auth-link gives the following error because it expects a token:

extensions: {path: "$", code: "invalid-headers"}
message: "Malformed Authorization header"

It needs to be update to the following so we only add the authorization if there is a token:

const authLink = setContext((_, { headers }) => {
    if (token) {
        return {
            headers: {
                ...headers,
                Authorization: `Bearer ${token}`
            }
        }
    }

    return headers
})