space issue in bearer token in react js

Advertisements

I m using Bearer token in my reactjs project and getting token form localstorage but space not coming properly between Bearer and Token

Code

const TOKEN = localStorage.getItem('TOKEN');
Axios.defaults.headers.common['Authorization'] = `Bearer ${TOKEN}`;

Result

Authorization: BearerN1ZuxkpgOlOfMGK3hrsl9N4UveoX-67hDH6jRDc5DgEA5yZpDxdyorIMCAeDV5vmHndKsapoYEqiXtoEPzT4vk6FQNOiQQRGdybZ-kfayEF2UaN7IJF0ui1nC8-hfpuzQddzBCg9PoskBzUJCc5ajYzp9VSNmo-nGtigEpyiqw7A5HDxi8GGytvkCGsM0-feW3FEy05VSKzkSu8pxTHR_Ism_uTTIxjrhiOEzMka5-qbhSQyTV1b5B_n_f_gsYX2

>Solution :

Your code formatter like prettier must be removing the space. In meantime you could use this line

Axios.defaults.headers.common['Authorization'] = 'Bearer'+' '+TOKEN;

Leave a ReplyCancel reply