Skip to content

Commit

Permalink
Handles the refresh token and access token time interval
Browse files Browse the repository at this point in the history
  - This patch  handles the time interval to make api calls
    to get new refresh token and access token for any time
    specified in api secrets

Signed-off-by: Puneet Punamiya <[email protected]>
  • Loading branch information
PuneetPunamiya authored and tekton-robot committed Mar 4, 2021
1 parent c302526 commit d29cf3d
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions ui/src/containers/UserProfile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,25 @@ const UserProfile: React.FC = () => {
const accessTokenInterval = user.accessTokenInfo.expiresAt * 1000 - new Date().getTime();
const refreshTokenInterval = user.refreshTokenInfo.expiresAt * 1000 - new Date().getTime();

// To get a new refresh token
// Update the refresh token before 10 seconds of current refresh token's expiry time
const tempRefreshId = window.setInterval(() => {
user.updateRefreshToken();
}, refreshTokenInterval - 10000);
setRefreshId(tempRefreshId);
// The condition checks the maximum delay for setInterval
if (refreshTokenInterval < Math.pow(2, 31) - 1) {
// To get a new refresh token
// Update the refresh token before 10 seconds of current refresh token's expiry time
const tempRefreshId = window.setInterval(() => {
user.updateRefreshToken();
}, refreshTokenInterval - 10000);
setRefreshId(tempRefreshId);
}

// To get a new access token
// Update the access token before 10 seconds of current access token's expiry time
const tempAccessId = window.setInterval(() => {
user.updateAccessToken();
}, accessTokenInterval - 10000);
setAccessId(tempAccessId);
// The condition checks the maximum delay for setInterval
if (accessTokenInterval < Math.pow(2, 31) - 1) {
// To get a new access token
// Update the access token before 10 seconds of current access token's expiry time
const tempAccessId = window.setInterval(() => {
user.updateAccessToken();
}, accessTokenInterval - 10000);
setAccessId(tempAccessId);
}
}, [user]);

useEffect(() => {
Expand Down

0 comments on commit d29cf3d

Please sign in to comment.