nathakits / spottie-figma-plugin

Spottie - A plugin for inserting Spotify artists and track images directly in Figma
MIT License
7 stars 1 forks source link

check if spotify token has expired #10

Open nathakits opened 3 years ago

nathakits commented 3 years ago

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 commented 3 years ago

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() } }