Skip to content

Commit

Permalink
Redirect to the login page instead of the logout page, when the user …
Browse files Browse the repository at this point in the history
…is already logged out
  • Loading branch information
askask committed Jun 17, 2024
1 parent e54a3d7 commit c853983
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/app/core/interceptors/error.interceptor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('ErrorInterceptor', () => {
let errorInterceptor: ErrorInterceptor

const authService = {
logout: () => {},
login: () => {},
} as AuthService

const profileService = {
Expand Down Expand Up @@ -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()
}
))
})
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/interceptors/error.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions src/app/core/interceptors/oauth.interceptor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('OAuthInterceptor', () => {
} as OAuthStorage

const authService = {
logOut: () => {},
initCodeFlow: () => {},
} as OAuthService

beforeEach(() => {
Expand Down Expand Up @@ -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()
}
))
})
Expand All @@ -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()
}
))
})
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/interceptors/oauth.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class OAuthInterceptor implements HttpInterceptor {

private handleError(error: HttpErrorResponse): Observable<never> {
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()
}
Expand Down

0 comments on commit c853983

Please sign in to comment.