Skip to content

Instantly share code, notes, and snippets.

@brunoksato
Created April 17, 2018 18:16
Show Gist options
  • Save brunoksato/1b19c69eec7766f4a6451e029c2ca53e to your computer and use it in GitHub Desktop.
Save brunoksato/1b19c69eec7766f4a6451e029c2ca53e to your computer and use it in GitHub Desktop.
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