React component for Spotify Implicit Grant Workflow login.
First of all: I (Benoît Hubert) am not really (or really not) the author of this component. It is indeed based on React GitHub Login from Checkr.
All credits go to Kurt Ruppel (main author) and Stewart Park (contributor).
I used the original component to help students build a project based on GitHub's API, and needed something similar to help another student build a project based on Spotify's API.
// index.js
import React from 'react';
import ReactDOM from 'react-dom';
import SpotifyLogin from 'react-spotify-login';
import { clientId, redirectUri } from './settings';
const onSuccess = response => console.log(response);
const onFailure = response => console.error(response);
ReactDOM.render(
<SpotifyLogin clientId={clientId}
redirectUri={redirectUri}
onSuccess={onSuccess}
onFailure={onFailure}/>,
document.getElementById('example')
);
Settings file example:
// settings.js
export const clientId = 'ac56fad434a3a3c1561e';
export const redirectUri = 'http://localhost:3000';
{string}
required
Client ID for Spotify OAuth application.
{string}
Registered redirect URI for Spotify OAuth application.
{string}
Scope for Spotify OAuth application. Defaults to user:email
.
{string}
CSS class for the login button.
{string}
Text content for the login button.
{function}
Callback for every request.
{function}
Callback for successful login. An object will be passed as an argument to the callback, e.g. { "access_token": "..." }
.
{function}
Callback for errors raised during login.
$ npm start
Webpack development server starts at http://localhost:8080, loading example/index.html.