Fix: also pass the custom authorization header in all requests
This commit is contained in:
@@ -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')
|
||||||
|
|||||||
Reference in New Issue
Block a user