mirror of
https://codeberg.org/SafeTwitch/safetwitch.git
synced 2025-04-12 21:31:19 -05:00
added twitch auth to get follows
This commit is contained in:
parent
255e730ab9
commit
6da9f778e0
1 changed files with 25 additions and 0 deletions
25
src/api/twitchAuth.ts
Normal file
25
src/api/twitchAuth.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
const TWITCH_CLIENT_ID = import.meta.env.VITE_TWITCH_CLIENT_ID;
|
||||
const INSTANCE_DOMAIN = import.meta.env.SAFETWITCH_INSTANCE_DOMAIN;
|
||||
const TWITCH_REDIRECT_URI = `${INSTANCE_DOMAIN}/auth/callback`;
|
||||
|
||||
export const initiateTwitchAuth = () => {
|
||||
const scopes = ['user:read:follows'];
|
||||
const authUrl = `https://id.twitch.tv/oauth2/authorize?client_id=${TWITCH_CLIENT_ID}&redirect_uri=${TWITCH_REDIRECT_URI}&response_type=token&scope=${scopes.join(' ')}`;
|
||||
window.location.href = authUrl;
|
||||
};
|
||||
|
||||
export const getFollowedChannels = async (accessToken: string) => {
|
||||
try {
|
||||
const response = await fetch('https://api.twitch.tv/helix/users/follows', {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${accessToken}`,
|
||||
'Client-Id': TWITCH_CLIENT_ID
|
||||
}
|
||||
});
|
||||
const data = await response.json();
|
||||
return data.data;
|
||||
} catch (error) {
|
||||
console.error('Error fetching followed channels:', error);
|
||||
return [];
|
||||
}
|
||||
};
|
Loading…
Add table
Reference in a new issue