Authorization headers for bearer token not being set

69 views Asked by At

I have been having this issue below where I login and do my authorisation and set the auth token in session storage and then set it in the headers. After I set it in the headers in my axiosConfig.js, I try to make a get request to another endpoint but it keeps giving me this error below. I have attached the code for the axiosConfig file. Please any help would be much appreciated.

Error screenshot:

enter image description here

axiosConfig.js:

import axios from "axios";

let AxiosInstance = axios.create({
  baseURL: {BASE_URL_ON_SEPARATE_SERVER},
  headers: {
    "Access-Control-Allow-Origin": "*",
    "Access-Control-Allow-Methods": "GET,POST,OPTIONS,DELETE,PUT",
  },
});

AxiosInstance.interceptors.request.use(function (config) {
  let token = JSON.parse(
    JSON.stringify(window.sessionStorage.getItem("api_key"))
  );
  config.headers["Authorization"] = "Bearer " + token;
  return config;
});

export default AxiosInstance;
0

There are 0 answers