I am not using any server like Express.js, so there is no server-to-server use case here.
My current goal is to simply using Axios to invoke twitch API like top-games: https://api.twitch.tv/helix/games/top
and then render the payload on my dashboard
This is my code for creating Axio instance here:
const api = axios.create({
headers: {
"client_id": "my client id",
"client_secret": 'my client secret',
"redirect_uri": 'http://localhost',
"grant_type": "client_credentials"
},
});
I am getting CORS error everytime when making the api call, the error message capture in console:
Access to XMLHttpRequest at 'https://api.twitch.tv/helix/games/top' from origin 'http://localhost:3000' has been blocked by CORS policy: Request header field grant_type is not allowed by Access-Control-Allow-Headers in preflight response.
Once you’ve got an access token, you can then make API requests. The Get Top Games example https://dev.twitch.tv/docs/api/reference#get-top-games shows what headers you should be sending, such as Client-ID, and Authorization.
For client-side requests you’ll use the Implicit auth flow, which means you need to actually send the user of your app there and if they approve your app they will be redirected back with an access token.
Once you have that access token you can make requests until that token expires, after which point you’ll need to send the user through the auth flow again.