Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check if spotify token has expired #10

Open
nathakits opened this issue Feb 27, 2021 · 1 comment
Open

check if spotify token has expired #10

nathakits opened this issue Feb 27, 2021 · 1 comment

Comments

@nathakits
Copy link
Owner

This could be done in several ways.

  1. execute getToken() and save it to a variable i.e. let token = getToken()
  2. then execute Search()
    try
    Search()
    catch (error)
    if error is because token has expired
    • run getToken() again
@nathakits
Copy link
Owner Author

nathakits commented Feb 27, 2021

the token expires in 1 hour, so could use date.now() to

async getToken() {
var token_response = get request
var expiration_time = token_response .expires_in (1 hour)
var start_time = Date.now()

var obj = {
token: "",
start_time: "",
expiration_time: ""
}
return obj
}

var Search() {
if (start_time - current_time < 1 expiration_time) {
get request
} else {
getToken()
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant