I have two headers, the first one contains APP_TOKEN and the second contains APP_TOKEN and USER_TOKEN, how do I condition if my request requires only APP_TOKEN or APP_TOKEN and USER_TOKEN on axios
this is my axios
import axios from 'axios'
export default axios.create((param_app){
if(param_app == APP_TOKEN){
baseURL: 'http://exampe',
headers: {
'timeout' : 30000,
'APP_TOKEN': 'apptoken_example',
}
}else if(param_app === APP_TOKEN && USER_TOKEN){
baseURL: 'http://exampe',
headers: {
'timeout' : 30000,
'APP_TOKEN': 'apptoken_example',
'USER_TOKEN': JSON.parse(localStorage.getItem('data')).TOKEN
}
}
})
for example this login page only requires APP_TOKEN for headers
async handleSubmit(e){
e.preventDefault()
if(this.state.MEMBER_EMAIL && this.state.MEMBER_PASSWORD){
const headers = {
'timeout' : 30000,
'APP_TOKEN': 'example',
}
await API.post('member/login', this.state ,{headers})
.then((response) => {
let responseJson = response
if(responseJson.data.STATUS_CODE === '200'){
this.props.resSave('data', JSON.stringify(responseJson.data.DATA))
this.setState({
redirect: true
})
}else if(responseJson.data.STATUS_CODE === '400') {
alert(responseJson.data.MESSAGE)
this.setState({
redirect: false
})
}
})
}
}
and this is an example of a page that requires APP_TOKEN and USER_TOKEN
async componentDidMount() {
const headers = {
'timeout' : 30000,
'APP_TOKEN': 'example',
'USER_TOKEN': JSON.parse(localStorage.getItem('data')).TOKEN
}
await API.get("/banner-home", {headers})
.then(response=>this.setState({
banner:response.data.DATA,
loading:false
}))
}