When I attempt to refresh a Podio access token by making a request to the refresh token endpoint within a Next.js API route, the token returned is often the old, stale token instead of a new one. However, when I perform the same operation in an identical, local script, the token refreshes correctly every time. Does anyone know if the refresh token endpoint distinguishes between calls made from server-side?
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Cache-Control", "no-store, max-age=0");
var raw = JSON.stringify({
grant_type: "refresh_token",
client_id: podio_app_id,
client_secret: client_key,
refresh_token: refresh_token,
});
var requestOptions = {
method: "POST",
headers: myHeaders,
body: raw,
};
const response = await fetch(
"https://api.podio.com/oauth/token/v2",
requestOptions
);
if (!response.ok) {
console.log(response);
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
console.log(data); // returns stale token in server. returns new token locally
I set a refresh_by time. If the current time exceeds refresh_by time, then a refresh is attempted server side. The token returned to the server is often stale, and the same token is returned repeatedly. The expected behavior is a new access token being returned with each call to the refresh endpoint.