const _initNetworkInterface = graphql_url => { const networkInterface = createNetworkInterface({ uri: graphql_url, opts: { credentials: 'same-origin' } }) // Authen networkInterface.use([{ applyMiddleware(req, next) { if (!req.options.headers) { req.options.headers = {} // Create the header object if needed. } // get the authentication token from local storage if it exists (async () => { const token = await persist.willGetSessionToken() req.options.headers.authorization = token ? `Bearer ${token}` : null next() })() } }]) return networkInterface }
applyMiddleware(req, next) { if (!req.options.headers) { req.options.headers = {}; // Create the header object if needed. } // get the authentication token from local storage if it exists const token = localStorage.getItem('id_token'); req.options.headers.authorization = token ? `Bearer ${token}` : null; next(); }