diff --git a/src/frontend/app/login/login.component.ts b/src/frontend/app/login/login.component.ts index fdd7eb719f33f0257278ed587e82426911d02dcf..d0b8dbbf58c6c000a9a7bdc880d94ce82cc92502 100644 --- a/src/frontend/app/login/login.component.ts +++ b/src/frontend/app/login/login.component.ts @@ -51,7 +51,7 @@ export class LoginComponent implements OnInit { }); this.environment = environment; - if (this.authService.isAuth()) { + if (this.authService.getToken() !== null) { if (!this.functionsService.empty(this.authService.getUrl(JSON.parse(atob(this.authService.getToken().split('.')[1])).user.id))) { this.router.navigate([this.authService.getUrl(JSON.parse(atob(this.authService.getToken().split('.')[1])).user.id)]); } else { diff --git a/src/frontend/service/app-light.guard.ts b/src/frontend/service/app-light.guard.ts index 2b2e7edef582700c1fe72d24abab762251310176..f2e066d243f2b851085da2a015ec5191fa9b0f12 100644 --- a/src/frontend/service/app-light.guard.ts +++ b/src/frontend/service/app-light.guard.ts @@ -35,7 +35,7 @@ export class AppLightGuard implements CanActivate { this.headerService.resetSideNavSelection(); return this.authService.getLoginInformations(state.url).pipe( - exhaustMap(() => this.authService.getToken() !== null ? this.authService.getCurrentUserInfo() : of(false)), + exhaustMap(() => this.authService.getToken() !== null && state.url !== '/login' ? this.authService.getCurrentUserInfo() : of(false)), map(() => true), catchError((err: any) => { return of(true); diff --git a/src/frontend/service/app.guard.ts b/src/frontend/service/app.guard.ts index 891e4f7d68f923449ba59686b7cb4dc937cef323..6c12f36e67387eb1cba860eb1e8d5d981461c571 100644 --- a/src/frontend/service/app.guard.ts +++ b/src/frontend/service/app.guard.ts @@ -38,7 +38,7 @@ export class AppGuard implements CanActivate { } else if (this.authService.getToken() === null) { this.authService.setCachedUrl(state.url.replace(/^\//g, '')); console.debug('Aucun token trouvé ! Redirection sur login ...'); - this.authService.logout(false); + this.authService.logout(false, true); return false; } }), diff --git a/src/frontend/service/auth-interceptor.service.ts b/src/frontend/service/auth-interceptor.service.ts index b172fe2762d11f369035cb2589075493d3f1311d..ef7f26009b4089748aca1cc86ced3208d00aef73 100644 --- a/src/frontend/service/auth-interceptor.service.ts +++ b/src/frontend/service/auth-interceptor.service.ts @@ -12,33 +12,33 @@ export class AuthInterceptor implements HttpInterceptor { byPassToken: any[] = [ { route: '../rest/prerequisites', - method : ['GET'] + method: ['GET'] }, { route: '../rest/authenticate', - method : ['POST'] + method: ['POST'] }, { route: '../rest/authenticate/token', - method : ['GET'] + method: ['GET'] }, { route: '../rest/authenticationInformation', - method : ['GET'] + method: ['GET'] }, { route: '../rest/passwordRules', - method : ['GET'] + method: ['GET'] }, { route: '../rest/languages', - method : ['GET'] + method: ['GET'] } ]; byPassHandleErrors: any[] = [ { route: '/password', - method : ['PUT'] + method: ['PUT'] } ]; constructor( @@ -61,7 +61,7 @@ export class AuthInterceptor implements HttpInterceptor { } logout() { - this.authService.logout(false); + this.authService.logout(false, true); this.notificationService.error(this.translate.instant('lang.sessionExpired')); } @@ -105,12 +105,7 @@ export class AuthInterceptor implements HttpInterceptor { catchError(err => { // Disconnect user if bad token process if (err.status === 401) { - if (this.router.url !== '/login' && this.router.url !== '/') { - this.logout(); - } else { - return next.handle(request); - } - + this.logout(); return of(false); } }) @@ -120,12 +115,8 @@ export class AuthInterceptor implements HttpInterceptor { catchError(err => { // Disconnect user if bad token process if (err.status === 401) { - console.debug('Refresh token failed !', request.url); - if (this.router.url !== '/login' && this.router.url !== '/') { - this.logout(); - } else { - return next.handle(request); - } + console.debug('Refresh token failed !', request.url, this.router.url); + this.logout(); } return of(false); }) diff --git a/src/frontend/service/auth.service.ts b/src/frontend/service/auth.service.ts index 8d7ac467eedcb8d06bb36cd95732c32e66bd9702..fd1e63a528feabcda4bd6168e0f471a0e043a2f4 100644 --- a/src/frontend/service/auth.service.ts +++ b/src/frontend/service/auth.service.ts @@ -102,8 +102,8 @@ export class AuthService { this.localStorage.remove('MaarchCourrierRefreshToken'); } - async logout(cleanUrl: boolean = true) { - if (['cas', 'keycloak'].indexOf(this.authMode) > -1) { + async logout(cleanUrl: boolean = true, forcePageLogin: boolean = false) { + if (['cas', 'keycloak'].indexOf(this.authMode) > -1 && !forcePageLogin) { this.SsoLogout(cleanUrl); } else { this.redirectAfterLogout(cleanUrl);