Reputation: 823
I have this header :
var header = {
'accept': 'application/json',
'x-application-id':applicationId,
'hashing': this.hashGenerator(location),
'content-type': 'application/json'
}
also I have some condition like this :
if(this.props.token != null){
header.access-token=this.props.token
}
but it seems I can't do like this to add a parameter
header.access-token
any idea to solve this ? Thanks beforehands.
Upvotes: 1
Views: 5463
Reputation: 469
instead of header.access-token=this.props.token
you can simply use json format as below
headers: {'Authorization': '[API key]'},
Upvotes: 0
Reputation: 3037
try: res.headers['access-token'] = this.props.token
and also, for custom headers you might need to add a "x-" prefix
see https://www.w3schools.com/js/js_object_properties.asp for more about object properties in JS
Upvotes: 2