Giter Club home page Giter Club logo

digital-music-friday's Introduction

Next.js Spotify OAuth Example

This repository is a Next.js project that includes an example of Spotify OAuth implementation. This allows users to log in via Spotify, granting the application certain permissions to access Spotify data, such as reading the user's playlists.

Table of Contents

Installation

To run this project, you will need to have Node.js and npm installed. If you don't have these installed, you can find instructions here.

  1. Clone the repository:

    git clone https://github.com/your-username/your-project-name.git
  2. Navigate into the project directory:

    cd your-project-name
  3. Install the dependencies:

    npm install

Getting Started

To start the development server, run the following command:

npm run dev

Then, navigate to http://localhost:3000 in your browser.

Environment Variables

Create an .env.local file at the root of your project and insert your environment variables:

SPOTIFY_CLIENT_ID=yourClientIDHere
SPOTIFY_CLIENT_SECRET=yourClientSecretHere
SPOTIFY_REDIRECT_URI=http://localhost:3000/api/spotify-callback

This project utilizes Spotify's API to create a musical experience. In order to get started, you'll need to register your app with Spotify to get the API Client ID and Secret.

Step-by-step Guide to Setup Spotify API Credentials

Step 1: Register Your App with Spotify

  1. Visit the Spotify Developer Dashboard.
  2. Log in to your Spotify account, or create a new one if you don't have one.
  3. Click on the 'Create an App' button.
  4. Fill in the name and description for your app, then click 'Create'.
  5. After your app is created, you will be redirected to a dashboard where you can see your Client ID and Client Secret.

Step 2: Copy the Client ID and Client Secret

  1. In the Spotify Developer Dashboard, locate the Client ID and Client Secret.
  2. Copy these credentials for the next step.

Step 3: Create .env.local file

  1. In your project root, create a new file named .env.local.
  2. Open this file in a text editor.

Step 4: Add Environment Variables

In your .env.local file, add the following lines, replacing yourClientIDHere and yourClientSecretHere with the credentials you copied earlier.

Important: Never commit .env.local to version control. It is in the .gitignore for security.

Project Structure

The main folders and files in this project are as follows:

  • pages/: Contains all the Next.js pages (React components).
  • pages/api/: Contains Next.js API routes.
  • components/: Contains reusable React components.

API Routes

  • GET /api/spotify-login: Redirects the user to Spotify's OAuth authorization page.
  • GET /api/spotify-callback: Handles the callback from Spotify and exchanges the authorization code for an access token.

Contributing

If you would like to contribute, please fork the repository and make changes as you'd like. Pull requests are warmly welcome.

digital-music-friday's People

Contributors

samsour avatar lauritzr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.