diff --git a/src/api/api.service.ts b/src/api/api.service.ts index a8bf86a..442ba05 100644 --- a/src/api/api.service.ts +++ b/src/api/api.service.ts @@ -1,4 +1,4 @@ -import {catchError, filter, mergeMap, Observable, retryWhen, switchMap, take, tap, timer} from "rxjs"; +import {catchError, filter, mergeMap, Observable, retryWhen, switchMap, tap, timer} from "rxjs"; import {HttpClient, HttpErrorResponse} from "@angular/common/http"; import {NotifyColor, OpenNotifyService} from "@service/open-notify.service"; import {environment} from "@environment"; @@ -144,7 +144,7 @@ export default abstract class ApiService implements SetRequestBuilderAfterBuild private handleError(error: HttpErrorResponse): void { // todo: change to Retry-After condition - if (error.error.toString().includes("setup")) { + if (error.error && error.error.toString().includes("setup")) { this.router.navigate(['/setup/']).then(); return; } diff --git a/src/api/v1/faculty.service.ts b/src/api/v1/faculty.service.ts index 7e188a3..0ce1902 100644 --- a/src/api/v1/faculty.service.ts +++ b/src/api/v1/faculty.service.ts @@ -13,7 +13,6 @@ export class FacultyService extends ApiService { .setQueryParams({page: page, pageSize: pageSize}) .build() .get(); - } public getById(id: number) { diff --git a/src/pages/login/login.component.ts b/src/pages/login/login.component.ts index 1fa593d..0d2fac4 100644 --- a/src/pages/login/login.component.ts +++ b/src/pages/login/login.component.ts @@ -11,7 +11,7 @@ import {FocusNextDirective} from "@/directives/focus-next.directive"; import {DataSpinnerComponent} from "@component/common/data-spinner/data-spinner.component"; import AuthApiService from "@api/v1/authApiService"; import {Router} from "@angular/router"; -import {catchError, of} from "rxjs"; +import {catchError} from "rxjs"; @Component({ selector: 'app-login', @@ -43,7 +43,7 @@ export class LoginComponent { constructor(private formBuilder: FormBuilder, private auth: AuthApiService, private route: Router) { this.auth.getRole() .subscribe(data => { - if (data != null) + if (data !== null) route.navigate(['admin']).then(); }); diff --git a/src/pages/setup/welcome/welcome.component.ts b/src/pages/setup/welcome/welcome.component.ts index fab5155..dd57ff4 100644 --- a/src/pages/setup/welcome/welcome.component.ts +++ b/src/pages/setup/welcome/welcome.component.ts @@ -29,7 +29,7 @@ export class WelcomeComponent { Validators.minLength(16) ]); - protected apiToGetToken : string = environment.apiUrl; + protected apiToGetToken: string = environment.apiUrl; constructor(private navigationService: NavigationService, private api: SetupService) { this.apiToGetToken += AvailableVersion[this.api.version]; diff --git a/src/services/auth.service.ts b/src/services/auth.service.ts index b153807..0b870a4 100644 --- a/src/services/auth.service.ts +++ b/src/services/auth.service.ts @@ -1,6 +1,6 @@ import {EventEmitter, Injectable} from '@angular/core'; import {HttpClient, HttpHeaders} from "@angular/common/http"; -import {catchError, Observable, of, tap} from "rxjs"; +import {Observable, tap} from "rxjs"; import {TokenResponse} from "@api/v1/tokenResponse"; import ApiService from "@api/api.service"; @@ -36,7 +36,6 @@ export class AuthToken { }) export class AuthService { public expireTokenChange = new EventEmitter(); - public tokenChangeError = new EventEmitter(); constructor(private http: HttpClient) { } @@ -60,8 +59,9 @@ export class AuthService { public refreshToken(): Observable { const token = localStorage.getItem(ApiService.tokenKey); + console.log(token); if (!token) - return of({} as TokenResponse); + throw new Error("token is not found"); const authToken = JSON.parse(token) as AuthToken; @@ -69,10 +69,6 @@ export class AuthService { case AvailableAuthenticationProvider.Bearer: return this.http.get(authToken.endpoint, {withCredentials: true}) .pipe( - catchError(error => { - this.tokenChangeError.emit(); - throw error; - }), tap(response => { const newExpireDate = new Date(response.expiresIn); const oldExpireDate = new Date(authToken.expiresIn); diff --git a/src/services/token-refresh.service.ts b/src/services/token-refresh.service.ts index ad8bd1f..957f86d 100644 --- a/src/services/token-refresh.service.ts +++ b/src/services/token-refresh.service.ts @@ -15,11 +15,6 @@ export class TokenRefreshService { constructor(private authService: AuthService) { this.setRefreshTokenExpireMs(AuthService.tokenExpiresIn.getTime() - 1000 - Date.now()); - authService.tokenChangeError.subscribe(_ => { - console.debug('Token change error event received'); - this.tokenRefreshing$.next(false); - this.stopTokenRefresh(); - }); authService.expireTokenChange.subscribe(date => { console.debug('Expire token change event received:', date); this.setRefreshTokenExpireMs(date.getTime() - 1000 - Date.now());