-
Notifications
You must be signed in to change notification settings - Fork 12
Middleware for Clients
Tim Scott edited this page Aug 27, 2017
·
7 revisions
Your API client needs a way to include the auth token in each request. React Devise provides middleware for this purpose.
The function addAuthorizationHeaderToRequest
takes request
as a parameter and adds to it an Authorization header with the auth token. It also, takes a next
callback as a second optional parameter.
This middleware is particularly useful when using a third party client like Apollo:
import ApolloClient, {createNetworkInterface} from 'apollo-client';
import {addAuthorizationHeaderToRequest} from 'react-devise';
const networkInterface = createNetworkInterface({
uri: '/graphql'
});
networkInterface.use([{
applyMiddleware: addAuthorizationHeaderToRequest
}]);