mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-12-11 00:57:09 +01:00
27 lines
677 B
TypeScript
27 lines
677 B
TypeScript
|
|
import { Injectable } from '@angular/core';
|
||
|
|
import {
|
||
|
|
HttpRequest,
|
||
|
|
HttpHandler,
|
||
|
|
HttpEvent,
|
||
|
|
HttpInterceptor
|
||
|
|
} from '@angular/common/http';
|
||
|
|
import { Observable } from 'rxjs';
|
||
|
|
import { AuthService } from './auth.service';
|
||
|
|
|
||
|
|
@Injectable()
|
||
|
|
export class AuthInterceptor implements HttpInterceptor {
|
||
|
|
|
||
|
|
constructor(private authService: AuthService) {}
|
||
|
|
|
||
|
|
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
|
||
|
|
if (this.authService.isAuthenticated()) {
|
||
|
|
request = request.clone({
|
||
|
|
setHeaders: {
|
||
|
|
Authorization: 'Token ' + this.authService.getToken()
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
return next.handle(request);
|
||
|
|
}
|
||
|
|
}
|