Created
April 17, 2018 18:16
-
-
Save brunoksato/1b19c69eec7766f4a6451e029c2ca53e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { create } from 'apisauce' | |
import Store from '../utils/store' | |
import { API_URL } from './constants' | |
const headers = { | |
Accept: 'application/json', | |
'Content-Type': 'application/json', | |
} | |
export const api = create({ | |
baseURL: API_URL, | |
headers | |
}) | |
api.addAsyncRequestTransform(request => async () => { | |
const resp = await Store.getToken() | |
if (request.url.indexOf('auth') !== -1) { | |
delete request.headers.Authorization | |
} else { | |
if (resp) { | |
request.headers.Authorization = `Bearer ${resp.token}` | |
} else { | |
// TODO DESLOGAR | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment