Add same getAuthToken logic to apollo transport

This commit is contained in:
Chi Vinh Le
2017-06-05 17:48:09 +07:00
parent defd28b20f
commit ac9e70bc67
2 changed files with 5 additions and 6 deletions
+1 -2
View File
@@ -9,7 +9,7 @@ import {getStore} from 'coral-framework/services/store';
* browsers that don't allow us to use cross domain iframe local storage.
* @return {string|null}
*/
const getAuthToken = () => {
export const getAuthToken = () => {
let state = getStore().getState();
if (state.config.auth_token) {
@@ -21,7 +21,6 @@ const getAuthToken = () => {
// Use local storage auth tokens where there's a stable api.
return Storage.getItem('token');
}
return null;
+4 -4
View File
@@ -1,6 +1,5 @@
import {createNetworkInterface} from 'apollo-client';
import * as Storage from '../helpers/storage';
import bowser from 'bowser';
import {getAuthToken} from '../helpers/request';
//==============================================================================
// NETWORK INTERFACE
@@ -23,8 +22,9 @@ networkInterface.use([{
req.options.headers = {}; // Create the header object if needed.
}
if (!bowser.safari && !bowser.ios) {
req.options.headers['authorization'] = `Bearer ${Storage.getItem('token')}`;
let authToken = getAuthToken();
if (authToken) {
req.options.headers['authorization'] = `Bearer ${authToken}`;
}
next();