Skip to content

Commit

Permalink
fix: updated reqs to include oAuth token
Browse files Browse the repository at this point in the history
  • Loading branch information
narajaon committed May 15, 2020
1 parent 8d657a1 commit 1b92fd5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
6 changes: 3 additions & 3 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"api_url": "https://api.twitch.tv/helix/",
"api_url_old": "https://api.twitch.tv/kraken/"
}
"api_url": "https://api.twitch.tv/helix",
"api_url_old": "https://api.twitch.tv/kraken"
}
1 change: 1 addition & 0 deletions instances/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Server {
req.api_url = config.api_url;
req.api_url_old = config.api_url_old;
req.client_id = secret.client_id;
req.client_secret = secret.client_secret;

next();
});
Expand Down
13 changes: 10 additions & 3 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,24 @@ function Index({ videos, error }) {

Index.getInitialProps = async ({ req }) => {
try {
const { data: oAuth2 } = await axios.post(
`https://id.twitch.tv/oauth2/token?client_id=${req.client_id}&client_secret=${req.client_secret}&grant_type=client_credentials`
);

const { data: games } = await axios.get(
`${req.api_url}games/top?first=15`,
`${req.api_url}/games/top?first=15`,
{
headers: { 'Client-ID': req.client_id }
headers: {
'Client-ID': req.client_id,
Authorization: `Bearer ${oAuth2.access_token}`
}
}
);

const res = await Promise.all(
games.data.map(({ name }) =>
axios.get(
`${req.api_url_old}clips/top?game=${name}&limit=10&trending=true`,
`${req.api_url_old}/clips/top?game=${name}&limit=10&trending=true`,
{
headers: {
'Client-ID': req.client_id,
Expand Down

0 comments on commit 1b92fd5

Please sign in to comment.