Disclaimer: I am currently building a more advanced project — Betterlist — designed for managing Spotify playlists without any hassle. Check it out for a more refined and smoother experience.
Source: Agê Barros
next-spotify-v2 is a simple project built with React 19 and Next.js 16 that fetches and displays data from the Spotify Web API. It uses Better Auth for login and Drizzle ORM for basic data handling.
Note: Currently, users cannot log in to the demo link due to Spotify's API Developer quota limits. The application is intended for local development and testing.
Working Demo: Vercel Link
- Framework: Next.js 16 (App Router)
- Library: React 19
- Language: TypeScript
- Authentication: Better Auth
- Database ORM: Drizzle ORM
- Database: Postgres - Neon provider
- Data Fetching: TanStack Query v5
- Client State: Zustand
- Styling: Tailwind CSS v4
- Linting and Formatting: Biome
- Icons: Lucide Icons
- Login: Authenticate with a Spotify account via Better Auth.
- Data Display: Fetches and lists top tracks, artists, and recently played tracks from the Spotify API.
- Library View: Displays your playlists, liked songs, followed artists, and albums.
Since Spotify's Redirect URIs often require HTTPS for authentication, you must use a tunneling service like ngrok for the login flow to work locally.
git clone https://github.com/ankitk26/next-spotify-app-router.git
cd next-spotify-app-router
npm installPush the database schema to your Postgres instance and start the server:
# Push schema
npx drizzle-kit push
# Run application
npm run dev- Install ngrok and authenticate it.
- Create a tunnel for your local server:
ngrok http 3000
- Copy the
ForwardingURL (e.g.,https://your-tunnel-id.ngrok-free.app).
Add the following environment variables to your .env file. Replace <YOUR_NGROK_URL> with the URL generated by ngrok.
DATABASE_URL=your_postgres_connection_string
SPOTIFY_CLIENT_ID=your_spotify_client_id
SPOTIFY_CLIENT_SECRET=your_spotify_client_secret
BETTER_AUTH_SECRET=your_generated_secret
BETTER_AUTH_URL=<YOUR_NGROK_URL>
- Go to the Spotify Developer Dashboard.
- Create an application to get your Client ID and Client Secret.
- Under Edit Settings, add the following Redirect URI:
<YOUR_NGROK_URL>/api/auth/callback/spotify
- Spotify API: Web API Documentation
- Authentication: Better Auth Documentation
- Database: Drizzle ORM Documentation
- Data Fetching: TanStack Query Docs
- Typography: Montserrat Font
- Dynamic Theming: Basic color extraction from album art.
- Error Handling: Basic boundaries for API rate limits.