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