Skip to content

Commit

Permalink
Avoid refreshing the token twice
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedHamouGisaia committed Feb 20, 2024
1 parent 4040514 commit a936984
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,14 @@ export class ArlasIamService extends ArlasAuthentificationService {
this.currentOrganisation = null;
}

/** This method should be called right after being logged in
* THUS; there is no need to refresh the token at 0; we can wait for the moment the token is about to expire to **start** the timer.
* By doing this we avoid refreshing the token twice in a row.
* Also starting the refresh at 0 causes some incoherence in localstorage when we activate 'redirect_uri' parameter in settings.yaml
*/
public startRefreshTokenTimer(loginData: LoginData): void {
const refreshToken = loginData.refresh_token;
this.tokenRefreshedSource.next(loginData);
if (!!refreshToken) {
// permit to obtain accessToken expiration date
const accessToken = loginData.access_token;
Expand All @@ -156,7 +162,7 @@ export class ArlasIamService extends ArlasAuthentificationService {
// todo: !! attention if the token expires in less than one minute !
// refresh accessToken when timeout ended (passing the refreshToken)
// start the delay after 0 seconds
this.refreshTokenTimer$ = timer(0, timeout).pipe(takeUntil(this.unsubscribe)).subscribe(() => {
this.refreshTokenTimer$ = timer(timeout, timeout).pipe(takeUntil(this.unsubscribe)).subscribe(() => {
const newestRefreshToken = this.getRefreshToken();
this.refresh(newestRefreshToken.value).subscribe({
next: (loginData: LoginData) => {
Expand Down

0 comments on commit a936984

Please sign in to comment.