From 3576ccdbf93d0fd489573d6d27f52a555d6be560 Mon Sep 17 00:00:00 2001 From: hexstudy Date: Sat, 7 Mar 2026 00:19:21 +0100 Subject: [PATCH] Delete src/app/interceptors/auth.interceptor.ts --- src/app/interceptors/auth.interceptor.ts | 55 ------------------------ 1 file changed, 55 deletions(-) delete mode 100644 src/app/interceptors/auth.interceptor.ts diff --git a/src/app/interceptors/auth.interceptor.ts b/src/app/interceptors/auth.interceptor.ts deleted file mode 100644 index 0b80230..0000000 --- a/src/app/interceptors/auth.interceptor.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { Injectable } from '@angular/core'; -import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent, HttpErrorResponse } from '@angular/common/http'; -import { Observable, throwError } from 'rxjs'; -import { catchError } from 'rxjs/operators'; - -@Injectable() -export class AuthInterceptor implements HttpInterceptor { - - intercept( - req: HttpRequest, - next: HttpHandler - ): Observable> { - const token = localStorage.getItem('token'); - - if (token && !req.url.includes('/login')) { - // Clona la richiesta e aggiungi gli header richiesti - req = req.clone({ - setHeaders: { - Authorization: `Bearer ${token}`, - 'REQUEST_METHOD': this.getRequestMethod(req.method) - } - }); - } - - return next.handle(req).pipe( - catchError((error: HttpErrorResponse) => { - // Log dell'errore nel browser (utile per debug) - console.error('Errore API:', error); - - // Gestisci errori 401 (non autorizzato) - if (error.status === 401) { - localStorage.removeItem('token'); - window.location.href = '/login'; - } - - return throwError(() => error); - }) - ); - } - - private getRequestMethod(method: string): string { - // Mappa i metodi HTTP standard - const methodMap: { [key: string]: string } = { - 'GET': 'GET', - 'POST': 'POST', - 'PUT': 'PUT', - 'DELETE': 'DELETE', - 'PATCH': 'PATCH', - 'HEAD': 'HEAD', - 'OPTIONS': 'OPTIONS' - }; - - return methodMap[method] || method; - } -} \ No newline at end of file