Malgré l'utilisation d'un jeton d'authentification fonctionnant théoriquement, la requête userQuery de UserProvider renvoie une valeur nulle user
et networkStatus de 7, indiquant que le chargement est terminé et qu'il n'y a pas d'erreur, "malgré que l'utilisateur soit nul.La requête utilisateur GraphQL graph.cool ne fonctionne pas avec le jeton Auth0
class UserProvider extends React.Component {
render() {
if (this.props.data.user) {
window.localStorage.setItem("userId", this.props.data.user.id)
}
if (this.props.data.loading) {
return <div>Loading</div>
}
return this.props.children(this.props.data.user)
}
}
const userQuery = gql`
query {
user {
id
}
}
`
export default graphql(userQuery, {
options: { fetchPolicy: "network-only" },
})(UserProvider)
Je configure l'interface réseau avec ce code.
const wsClient = new SubscriptionClient(
`wss://subscriptions.graph.cool/v1/redacted`,
{
reconnect: true,
}
)
const networkInterface = createNetworkInterface({
uri: "https://api.graph.cool/simple/v1/redacted",
})
const networkInterfaceWithSubscriptions = addGraphQLSubscriptions(
networkInterface,
wsClient
)
networkInterfaceWithSubscriptions.use([
{
applyMiddleware(req, next) {
if (!req.options.headers) {
req.options.headers = {}
}
console.log("applying middleware")
// get the authentication token from local storage if it exists
if (localStorage.getItem("auth0IdToken")) {
console.log("apply header", localStorage.getItem("auth0IdToken"))
req.options.headers["Authorization"] = `Bearer ${localStorage.getItem(
"auth0IdToken"
)}`
}
next()
},
},
])
let client = new ApolloClient({
networkInterface: networkInterfaceWithSubscriptions,
})