Skip to content

Instantly share code, notes, and snippets.

@gate5th
Created September 12, 2018 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gate5th/61fc1959ad6e69fd7029d189d59f0964 to your computer and use it in GitHub Desktop.
Save gate5th/61fc1959ad6e69fd7029d189d59f0964 to your computer and use it in GitHub Desktop.
oldschoolshuffle
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