Add a control to avoid error notif at login failure.

This commit is contained in:
2020-01-18 14:30:17 +01:00
parent 84b1dd6352
commit 5e5fbd9377

View File

@@ -6,6 +6,8 @@ import { catchError } from 'rxjs/operators';
import { AuthService } from '../services/auth.service'; import { AuthService } from '../services/auth.service';
import { NotificationsComponent } from '../notifications/notifications.component'; import { NotificationsComponent } from '../notifications/notifications.component';
const REG_URL_LOGIN = /^https?:\/\/.*(:\d{1,5})?\/api\/account\/login$/;
@Injectable() @Injectable()
export class UnauthorizedInterceptor implements HttpInterceptor { export class UnauthorizedInterceptor implements HttpInterceptor {
constructor( constructor(
@@ -18,7 +20,9 @@ export class UnauthorizedInterceptor implements HttpInterceptor {
if (err.status === 401) { if (err.status === 401) {
this.authService.setAnonymous(); this.authService.setAnonymous();
this.router.navigate(['/login']); this.router.navigate(['/login']);
window.setTimeout(() => NotificationsComponent.error('Veuillez vous authentifier pour réaliser cette action.'), 500); if (!err.url.match(REG_URL_LOGIN)) {
window.setTimeout(() => NotificationsComponent.error('Veuillez vous authentifier pour réaliser cette action.'), 500);
}
} }
const error = (err.error && err.error.message) || err.statusText; const error = (err.error && err.error.message) || err.statusText;