0
let headers = {
            "Content-Type": "application/json",
            "Authorization": "token=" + this.props.login.token,
            "Accept-Language": this.props.language.language,
        };
1
  • 1
    login prop is undefined. How do you pass the login prop to the component? Please give more details. Commented Jan 14, 2020 at 5:58

2 Answers 2

1

I think you are passing token in wrong way

instead of writing like this

"Authorization": "token=" + this.props.login.token,

define like this

"Authorization": "bearer " + this.props.login.token,

Sample of axios code

axios.post('api_ulr', {
  headers: {'Authorization': "bearer " + this.props.login.token}
  }
).then((response) => {
  console.log(response)
}).catch((error) => {
  console.log(error)
});
Sign up to request clarification or add additional context in comments.

Comments

0

Issue solved. Actually when calling a component and if you don't provide props along with that, we get this error "Cannot read property 'token' of undefined". So just pass the props along with the component like {...this.props} and it works well.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.