fix: unsubscribe from listening to refresh token
This commit is contained in:
parent
5d79d86c44
commit
60d306f9c9
@ -1,4 +1,4 @@
|
||||
import {catchError, filter, mergeMap, Observable, retryWhen, switchMap, timer} from "rxjs";
|
||||
import {catchError, distinctUntilChanged, filter, first, mergeMap, Observable, retryWhen, switchMap, timer} from "rxjs";
|
||||
import {HttpClient, HttpErrorResponse} from "@angular/common/http";
|
||||
import {NotifyColor, OpenNotifyService} from "@service/open-notify.service";
|
||||
import {environment} from "@environment";
|
||||
@ -94,7 +94,9 @@ export default abstract class ApiService {
|
||||
private makeHttpRequest<Type>(method: 'get' | 'post' | 'delete' | 'put', request: RequestData): Observable<Type> {
|
||||
if (request.needAuth)
|
||||
return this.tokenRefreshService.getTokenRefreshing$().pipe(
|
||||
distinctUntilChanged(),
|
||||
filter(isRefreshing => !isRefreshing),
|
||||
first(),
|
||||
switchMap(() => {
|
||||
const token = localStorage.getItem(ApiService.tokenKey);
|
||||
|
||||
|
@ -26,23 +26,21 @@ export class TokenRefreshService {
|
||||
}
|
||||
|
||||
private refreshToken(): void {
|
||||
if (this.tokenRefreshing$.value) {
|
||||
if (this.tokenRefreshing$.value)
|
||||
return;
|
||||
}
|
||||
|
||||
this.tokenRefreshing$.next(true);
|
||||
|
||||
this.authService.refreshToken()
|
||||
.pipe(
|
||||
catchError(error => {
|
||||
catchError(_ => {
|
||||
localStorage.removeItem(ApiService.tokenKey);
|
||||
this.refreshTokenExpireMs = -1;
|
||||
return of(undefined);
|
||||
}))
|
||||
.subscribe(data => {
|
||||
if (data) {
|
||||
if (data)
|
||||
this.setRefreshTokenExpireMs(data);
|
||||
}
|
||||
this.tokenRefreshing$.next(false);
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user