Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/app/modules/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,12 @@ export class LoginComponent implements OnInit {
ngOnInit() {

this.googleAuthSDK();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviisale si esta linea no te da conflictos porque es del Auth de google

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();
Expand Down
18 changes: 16 additions & 2 deletions src/app/modules/shared/interceptors/inject.token.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (request.url.startsWith(environment.timeTrackerApiUrl)) {
Expand All @@ -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);
}
Expand Down