spotifyLogin = async (clientId, params = {}) => {
let output
const spotifyToken = new URLSearchParams(window.location.hash.replace('#', '?')).get('access_token')
if (!spotifyToken) {
output = loginButton(clientId, params)
} else {
const spotifyProfileResponse = await fetch(
'https://api.spotify.com/v1/me',
{ headers: { Authorization: `Bearer ${spotifyToken}` } }
)
const spotifyProfile = await spotifyProfileResponse.json()
output = profileDetails(spotifyProfile)
}
return Object.assign(output, { value: spotifyToken })
}