N
N
Nikita2021-10-29 17:20:03
React
Nikita, 2021-10-29 17:20:03

How to specify authorization token in react apollo?

How to pass the Bearer token authorization header in this case?

const wsLink = new WebSocketLink({
    uri: 'wss://domen/v1/graphql',
    options: {
        reconnect: true
    }
})

const httpLink = new HttpLink({
    uri: 'https://domen/v1/graphql',
})

const client = new ApolloClient({
    link: split(
        ({ query }) => {
            const { kind, operation } = getMainDefinition(query)

            return (
                kind === 'OperationDefinition' &&
                operation === 'subscription'
            )
        },
        wsLink,
        httpLink,
    ),
    cache: new InMemoryCache()
})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolay Matyushkin, 2021-10-30
@Devilz_1

I hope this example will help you!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question