I currently have a refresh token API call after every 60 mints,
Here is my condition:
**const expires_in = 3600 //This is 3600s comes from auth api
if (refreshToken && expires_in * 1000 > Date.now() + 3600000) {
// RefreshToken Function
else {
console.log("accessToken not expired yet");
}**
This condition is not work properly. This condition call RefreshToken Function on every reload but I want to call this after every 60 minutes.
Accurate my condition which is call after every 60 minutes.
2
Answers
Can you not just use a sleep function, or something like that ?
expires_in * 1000 = 3600000 ,
Date.now() + 3600000 = 1720672843350 ,
So the condition can never be true.
Also your could should look like:
In this case you are expecting both conditions to be true to execute the function.
But here as I told you :
The first condition can never be greater than the second one, which means you will never be able to execute the function according to your condition.
Maybe you wanted to say:
}
My advice is to correct the math first and figure out what exactly should the condition be like.