Is there a way to remove the authorization bear token in the second request?

I am trying to upload to Cloudflare. I am generating the upload URL at my sever and send 201 back and set Location header [videodelivery.net ]. Al those works fine.

However, my own server is using a bearer token for authorization, but the same authorization header is been sent to videodelivery.net, which is then get rejected due to

Access to XMLHttpRequest at 'https://upload.videodelivery.net/0xxxxb?tusv2=true' from origin '' has been blocked by CORS policy: Request header field authorization is not allowed by Access-Control-Allow-Headers in preflight response.

is there a way for me to remove the authorization header in the direction request?

thanks

2 Likes

So, the way i have handled that part is something like this:

          onBeforeRequest: (req) => {
            return new Promise((resolve) => {
              let xhr: XMLHttpRequest = req.getUnderlyingObject();
              if (req.getURL().includes(import.meta.env.VITE_BACKEND_URL)) {
                xhr.withCredentials = true;

                //ignore this. 
                let token = sessionStorage.getItem("authToken");
                if (token) {
                  xhr.setRequestHeader("Authorization", token);
                }
              } else {
                // set to false or else because its been true it will set true in second request.
                xhr.withCredentials = false;
              }
              resolve(() => {});
            });
          },