mirror of
https://github.com/wassname/talk.git
synced 2026-07-24 13:20:47 +08:00
Add same getAuthToken logic to apollo transport
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user