The code creates a function that will refresh the authentication token after it has expired. It sets a delay so that the token will be refreshed every hour.
export const refreshTokenSetup = (res) => {
let refreshTiming = (res.tokenObj.expires_in || 3600 - 5 * 60) * 1000;
const refreshToken = async () => {
const newAuthRes = await res.reloadAuthResponse();
refreshTiming = (newAuthRes.expires_in || 3600 - 5 * 60) * 1000;
console.log(`newAuthRes`, newAuthRes);
setTimeout(refreshToken, refreshTiming);
};
setTimeout(refreshToken, refreshTiming);
};