"use client"; import { SearchResults, SpotifyApi } from "@sdk/index.js"; // use "@spotify/web-api-ts-sdk" in your own project import sdk from "@/lib/spotify-sdk/ClientInstance"; import { useSession, signOut, signIn } from "next-auth/react"; import { useEffect, useState } from "react"; export default function Home() { const session = useSession(); if (!session || session.status !== "authenticated") { return (

Spotify Web API Typescript SDK in Next.js

); } return (

Logged in as {session.data.user?.name}

); } function SpotifySearch({ sdk }: { sdk: SpotifyApi }) { const [results, setResults] = useState({} as SearchResults); useEffect(() => { (async () => { const results = await sdk.search("The Beatles", ["artist"]); setResults(() => results); })(); }, [sdk]); // generate a table for the results const tableRows = results.artists?.items.map((artist) => { return ( {artist.name} {artist.popularity} {artist.followers.total} ); }); return ( <>

Spotify Search for The Beatles

{tableRows}
Name Popularity Followers
); }