Skip to content

Commit

Permalink
feat: implement get user shows service
Browse files Browse the repository at this point in the history
  • Loading branch information
okanisildar committed Dec 11, 2023
1 parent f17e74f commit 55a395f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/(auth)/auth/sign-in/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export async function POST(request: NextRequest) {
const supabase = createSupabaseServerClient(cookies());
const redirectURL = new URL('/auth/callback', request.url);

const scopes = 'user-read-email user-read-playback-position';
const scopes =
'user-read-email user-read-playback-position user-library-read';
const result = await supabase.auth.signInWithOAuth({
options: {
redirectTo: redirectURL.toString(),
Expand Down
36 changes: 36 additions & 0 deletions lib/services/spotify/get-user-shows.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
type Show = {
description: string;
id: string;
images: string;
language: string;
name: string;
publisher: string;
total_episodes: number;
};

type Items = {
added_at: string;
show: Show;
};

type SpotifyItems = {
items: Items;
limit: number;
offset: number;
};

export const getUserShows = async (spotifyToken: string): Promise<Items> => {
try {
const response = await fetch('https://api.spotify.com/v1/me/shows', {
headers: {
Authorization: `Bearer ${spotifyToken}`,
},
method: 'GET',
});

const { items } = (await response.json()) as SpotifyItems;
return items;
} catch (e) {
throw Error('Could not get shows from spotify');
}
};

0 comments on commit 55a395f

Please sign in to comment.