Created
September 12, 2018 18:44
-
-
Save gate5th/61fc1959ad6e69fd7029d189d59f0964 to your computer and use it in GitHub Desktop.
oldschoolshuffle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function redirectUrlToSpotifyForLogin(){ | |
var CLIENT_ID = process.env.REACT_APP_SPOTIFY_CLIENT_ID; | |
var REDIRECT_URI = process.env.REACT_APP_SPOTIFY_REDIRECT_URI; | |
const scopes = [ | |
"user-modify-playback-state", | |
"user-library-read", | |
"user-library-modify", | |
"playlist-read-private", | |
"playlist-modify-public", | |
"playlist-modify-private"]; | |
return 'https://accounts.spotify.com/authorize?client_id=' + CLIENT_ID + | |
'&redirect_uri=' + encodeURIComponent(REDIRECT_URI) + | |
'&scope=' + encodeURIComponent(scopes.join(' ')) + | |
'&response_type=token'; | |
} | |
export function checkUrlForSpotifyAccessToken(){ | |
const params = getHashParams(); | |
const accessToken = params.access_token | |
if (!accessToken) { | |
return false | |
} | |
else { | |
return accessToken | |
} | |
} | |
function getHashParams() { | |
//helper function to parse the query string that spotify sends back when you log in | |
var hashParams = {}; | |
var e, r = /([^&;=]+)=?([^&;]*)/g, | |
q = window.location.hash.substring(1); | |
// eslint-disable-next-line | |
while ( e = r.exec(q)) { | |
hashParams[e[1]] = decodeURIComponent(e[2]); | |
} | |
return hashParams; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment