This project demonstrates OAuth 2.0 authentication via the Authorization Code Flow for the Spotify Web API using Netlify serverless functions. In essence, the Spotify Web API example has been adapted to use Netlify functions on the backend and Create React App on the frontend.
Use your Spotify account on the Spotify developer site to create an app and get a Client ID and Client Secret. You need to set up your redirect URI on the Spotify dashboard.
http://localhost:8888/.netlify/functions/callback
Create a file called .env to store environment variables.
REACT_APP_CLIENT_ID="your client id here"
REACT_APP_CLIENT_SECRET="your client secret here"
Never share your Client ID in public such as in a git repository.
In the project directory, install the packages:
yarn
Set up Netlify CLI if you have not done so.
npm install netlify-cli -g
Login to your Netlify account:
ntl login
Start the app:
ntl dev
Open http://localhost:8888 to view it in the browser.