diff --git a/src/app/modules/login/login.component.ts b/src/app/modules/login/login.component.ts index 792fc56e..91ad64a6 100644 --- a/src/app/modules/login/login.component.ts +++ b/src/app/modules/login/login.component.ts @@ -64,15 +64,12 @@ export class LoginComponent implements OnInit { ngOnInit() { this.googleAuthSDK(); - if (this.isProduction && this.azureAdB2CService.isLogin()) { - this.router.navigate(['']); - } else { this.loginService.isLogin().subscribe(isLogin => { if (isLogin) { this.router.navigate(['']); } }); - } + window.handleCredentialResponse = (response) => { const {credential = ''} = response; this.featureToggleCookiesService.setCookies(); diff --git a/src/app/modules/shared/interceptors/inject.token.interceptor.ts b/src/app/modules/shared/interceptors/inject.token.interceptor.ts index b1310044..d045b0e6 100644 --- a/src/app/modules/shared/interceptors/inject.token.interceptor.ts +++ b/src/app/modules/shared/interceptors/inject.token.interceptor.ts @@ -4,18 +4,22 @@ import { HttpInterceptor, HttpHandler, HttpRequest, + HttpErrorResponse, } from '@angular/common/http'; import { Observable } from 'rxjs'; +import { tap } from 'rxjs/operators'; import { AzureAdB2CService } from 'src/app/modules/login/services/azure.ad.b2c.service'; import { environment } from './../../../../environments/environment'; import { EnvironmentType } from 'src/environments/enum'; import { LoginService } from '../../login/services/login.service'; +import { catchError } from 'rxjs/operators'; +import { Router } from '@angular/router'; @Injectable() export class InjectTokenInterceptor implements HttpInterceptor { isProduction = environment.production === EnvironmentType.TT_PROD_LEGACY; - constructor(private azureAdB2CService: AzureAdB2CService, private loginService: LoginService) { } + constructor(private azureAdB2CService: AzureAdB2CService, private loginService: LoginService, private router: Router) { } intercept(request: HttpRequest, next: HttpHandler): Observable> { if (request.url.startsWith(environment.timeTrackerApiUrl)) { @@ -25,7 +29,17 @@ export class InjectTokenInterceptor implements HttpInterceptor { headers: request.headers.set('Authorization', 'Bearer ' + token) }); - return next.handle(requestWithHeaders); + return next.handle(requestWithHeaders) + .pipe( + tap(() => { }, (err: any) => { + if (err instanceof HttpErrorResponse) { + if (err.status === 401) { + this.loginService.logout(); + window.open("/login", "_self") + } + } + }) + ); } else { return next.handle(request); }