Fix: also pass the custom authorization header in all requests

This commit is contained in:
Deluan 2020-04-06 16:23:47 -04:00
parent 3f9ddb915e
commit c1afe70d98
1 changed files with 3 additions and 2 deletions

View File

@ -3,6 +3,7 @@ import jsonServerProvider from 'ra-data-json-server'
import baseUrl from './utils/baseUrl'
const restUrl = '/app/api'
const customAuthorizationHeader = 'X-ND-Authorization'
const httpClient = (url, options = {}) => {
url = baseUrl(url)
@ -12,10 +13,10 @@ const httpClient = (url, options = {}) => {
}
const token = localStorage.getItem('token')
if (token) {
options.headers.set('X-ND-Authorization', `Bearer ${token}`)
options.headers.set(customAuthorizationHeader, `Bearer ${token}`)
}
return fetchUtils.fetchJson(url, options).then((response) => {
const token = response.headers.get('authorization')
const token = response.headers.get(customAuthorizationHeader)
if (token) {
localStorage.setItem('token', token)
localStorage.removeItem('initialAccountCreation')