All files / src/spotify-api auth.js

100% Statements 13/13
50% Branches 1/2
100% Functions 3/3
100% Lines 13/13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 454x 4x     8x                     4x                     4x   4x 1x 1x       3x 3x 3x         1x 1x    
let REACT_APP_CLIENT_ID = process.env.REACT_APP_CLIENT_ID;
let REACT_APP_REDIRECT_URI = process.env.REACT_APP_REDIRECT_URI;
 
function getLoginURL(scopes) {
  return (
    "https://accounts.spotify.com/authorize?client_id=" +
    REACT_APP_CLIENT_ID +
    "&redirect_uri=" +
    encodeURIComponent(REACT_APP_REDIRECT_URI) +
    "&scope=" +
    encodeURIComponent(scopes.join(" ")) +
    "&response_type=token"
  );
}
 
export const url = getLoginURL([
  "user-read-private",
  "playlist-read-private",
  "playlist-modify-public",
  "playlist-modify-private",
  "user-library-read",
  "user-library-modify",
  "user-follow-read",
  "user-follow-modify"
]);
 
export const publicurl = getLoginURL([]);
 
export const decodeHash = function(locationhash) {
  var hash = {};
  locationhash
    .replace(/^#\/?/, "")
    .split("&")
    .forEach(function(kv) {
      var spl = kv.indexOf("=");
      Eif (spl !== -1) {
        hash[kv.substring(0, spl)] = decodeURIComponent(kv.substring(spl + 1));
      }
    });
 
  //console.log('initial hash', hash);
  hash.expirationTime = new Date().getTime() + Number(hash.expires_in) * 1000;
  return hash;
};