I have problem with setting authorization header in the axios GET request. I've done a lot of research, but didn't find solution. Also I checked the CORS settings and it supposed to be ok and the request is working from postman or advance rest client, so I don't believe thats the problem on the server side.
My function with axios request
export function getUserInfo (userId) { return function (dispatch) { axios.get(`${ROOT_URL}/user/${userId}`, helperMethods.authorizedHeader()) .then(response => { dispatch({type: USER_INFO, payload: response.data.message}); }) .catch(error => { console.log('something went wrong: ', error); }); }; } Helper method (which is returning valid object, I debugged it)
export function authorizedHeader () { let token = sessionStorage.getItem(TOKEN); if (!token) { token = localStorage.getItem(TOKEN); } return { headers: { 'Accept': 'application/json', 'Authorization': `${token}` } }; } And CORS settings:
@Bean public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = new CorsConfiguration(); config.setAllowCredentials(true); config.addAllowedOrigin("*"); config.addAllowedHeader("*"); config.addAllowedMethod("*"); source.registerCorsConfiguration("/**", config); return new CorsFilter(source); } So if you have any advice please share it with me.
Thank you