Skip to content

Commit

Permalink
Refresh on token expiry
Browse files Browse the repository at this point in the history
  • Loading branch information
xaymup committed Jul 27, 2024
1 parent 69364b4 commit a7c31b7
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,21 @@ function init() {
document.getElementById('email-form').style.display = 'none';
document.getElementById('dj-set-form').style.display = 'block';
loadGenres(); // Load genres when the user is authenticated
tokenExpire(redirectUri);
} else {
document.getElementById('login-button').style.display = 'block';
document.getElementById('email-form').style.display = 'block';
document.getElementById('dj-set-form').style.display = 'none';
}
}

function tokenExpire(url) {
// 3600 seconds = 3600 * 1000 milliseconds
setTimeout(function() {
window.location.href = url;
}, 3600 * 1000);
}

function authenticate() {
const scopes = 'user-read-private user-read-email playlist-modify-private';
window.location = `https://accounts.spotify.com/authorize?client_id=${clientId}&response_type=token&redirect_uri=${encodeURIComponent(redirectUri)}&scope=${encodeURIComponent(scopes)}`;
Expand Down

0 comments on commit a7c31b7

Please sign in to comment.