У меня есть сервер Prisma с настройкой Apache Basic Auth, отлично работает в React-Native ... однако в нашем проекте React.js заголовок auth никогда не добавляется.
import React, {Component} from 'react'
import { ApolloClient } from 'apollo-client'
import { createHttpLink } from 'apollo-link-http'
import { setContext } from 'apollo-link-context'
import { InMemoryCache } from 'apollo-cache-inmemory'
import { ApolloProvider } from 'react-apollo'
import Home from './Container'
const httpLink = createHttpLink({
uri: 'https://app.url/graphql',
fetchOptions: {
mode: 'no-cors',
},
})
const authLink = setContext((_, { headers }) =>
// get the authentication token from local storage if it exists
// const token = localStorage.getItem('token');
// return the headers to the context so httpLink can read them
({
headers: {
Authorization: 'Basic base64goeshere',
...headers,
},
})
)
const client = new ApolloClient({
link: authLink.concat(httpLink),
cache: new InMemoryCache(),
})
export default class WithProvider extends Component {
render() {
return (
<ApolloProvider client={client}>
<Home auth={this.props.auth} />
</ApolloProvider>
)
}
}
В результате отсутствуют заголовки аутентификации, а в результате отсутствия заголовка возникает ошибка 401.