diff --git a/src/app/core/interceptors/error.interceptor.spec.ts b/src/app/core/interceptors/error.interceptor.spec.ts index b813c7b02..a115fd891 100644 --- a/src/app/core/interceptors/error.interceptor.spec.ts +++ b/src/app/core/interceptors/error.interceptor.spec.ts @@ -9,7 +9,7 @@ describe('ErrorInterceptor', () => { let errorInterceptor: ErrorInterceptor const authService = { - logout: () => {}, + login: () => {}, } as AuthService const profileService = { @@ -47,12 +47,12 @@ describe('ErrorInterceptor', () => { const mockErrorResponse = { status: 401, statusText: 'Unauthorized' } const data = 'Unauthorized' - jest.spyOn(injectedAuthService, 'logout') + jest.spyOn(injectedAuthService, 'login') http.get('/data').subscribe() httpMock.expectOne('/data').flush(data, mockErrorResponse) - expect(injectedAuthService.logout).toHaveBeenCalled() + expect(injectedAuthService.login).toHaveBeenCalled() } )) }) diff --git a/src/app/core/interceptors/error.interceptor.ts b/src/app/core/interceptors/error.interceptor.ts index 7808d8761..ff65b89ba 100644 --- a/src/app/core/interceptors/error.interceptor.ts +++ b/src/app/core/interceptors/error.interceptor.ts @@ -16,7 +16,7 @@ export class ErrorInterceptor implements HttpInterceptor { return next.handle(request).pipe( catchError((err) => { if (err.status === 401) { - this.authService.logout() + this.authService.login(window.location.href) } if (err.status === 403) { this.profileService.setUnapproveUser(true) diff --git a/src/app/core/interceptors/oauth.interceptor.spec.ts b/src/app/core/interceptors/oauth.interceptor.spec.ts index b217540d6..435a8f60b 100644 --- a/src/app/core/interceptors/oauth.interceptor.spec.ts +++ b/src/app/core/interceptors/oauth.interceptor.spec.ts @@ -12,7 +12,7 @@ describe('OAuthInterceptor', () => { } as OAuthStorage const authService = { - logOut: () => {}, + initCodeFlow: () => {}, } as OAuthService beforeEach(() => { @@ -75,12 +75,12 @@ describe('OAuthInterceptor', () => { const mockErrorResponse = { status: 401, statusText: 'Unauthorized' } const data = 'Unauthorized' - jest.spyOn(injectedAuthService, 'logOut') + jest.spyOn(injectedAuthService, 'initCodeFlow') http.get('/data').subscribe() httpMock.expectOne('/data').flush(data, mockErrorResponse) - expect(injectedAuthService.logOut).toHaveBeenCalled() + expect(injectedAuthService.initCodeFlow).toHaveBeenCalled() } )) }) @@ -92,12 +92,12 @@ describe('OAuthInterceptor', () => { const mockErrorResponse = { status: 500, statusText: 'Internal Server Error' } const data = 'Internal Server Error' - jest.spyOn(injectedAuthService, 'logOut') + jest.spyOn(injectedAuthService, 'initCodeFlow') http.get('/data').subscribe() httpMock.expectOne('/data').flush(data, mockErrorResponse) - expect(injectedAuthService.logOut).not.toHaveBeenCalled() + expect(injectedAuthService.initCodeFlow).not.toHaveBeenCalled() } )) }) diff --git a/src/app/core/interceptors/oauth.interceptor.ts b/src/app/core/interceptors/oauth.interceptor.ts index 5830634d0..1842c8413 100644 --- a/src/app/core/interceptors/oauth.interceptor.ts +++ b/src/app/core/interceptors/oauth.interceptor.ts @@ -35,7 +35,7 @@ export class OAuthInterceptor implements HttpInterceptor { private handleError(error: HttpErrorResponse): Observable { if (error.status === 401) { - this.oauthService.logOut() + this.oauthService.initCodeFlow(window.location.href) } else if (error.status === 409 && error.url.includes('/admin/user/')) { return of() }