CORS error persists in oAuth even after setting header

@BarryCarlyon This is because I edited the actual error message (wanted to remove some jibberish just to make it a bit more readable). My bad.

I got your point but How am I supposed to do that?

One more thing I want to point out is that when I open the server link (http://localhost:3001/auth/twitch/callback) in a new tab, I am redirected to twitch and everything works fine and I am able to get the access_token.
The error only occurs when I try to access the endpoint from the frontend.
I think I know what the problem is but don’t know how to solve it.
Below is the screenshot of my network log:

Here we can see that the authorization request successfully redirects the login/authorization page to the frontend but since this page is sent from twitch and my origin is different so the cors error occurs and the below error is thrown:

I think this is the problem (Point me if I am wrong here). So the only thing which I can’t figure out is that how to redirect to twitch directly from the frontend and at the same time hit my backend API because all my authorization code is written there?