Skip to content

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.

Use With Apollo

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
}]);

NEXT: Devise Server Setup >

Clone this wiki locally