mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-12-12 09:37:04 +01:00
use django authentication instead of auth tokens.
This commit is contained in:
parent
e81f7e0430
commit
7bd843283d
24 changed files with 172 additions and 328 deletions
|
|
@ -1,37 +0,0 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import {
|
||||
HttpRequest,
|
||||
HttpHandler,
|
||||
HttpEvent,
|
||||
HttpInterceptor,
|
||||
HttpErrorResponse
|
||||
} from '@angular/common/http';
|
||||
import { Observable, throwError } from 'rxjs';
|
||||
import { AuthService } from './auth.service';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
import { Toast, ToastService } from './toast.service';
|
||||
|
||||
@Injectable()
|
||||
export class AuthInterceptor implements HttpInterceptor {
|
||||
|
||||
constructor(private authService: AuthService, private toastService: ToastService) {}
|
||||
|
||||
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).pipe(
|
||||
catchError((error: HttpErrorResponse) => {
|
||||
if (error.status == 401 && this.authService.isAuthenticated()) {
|
||||
this.authService.logout()
|
||||
this.toastService.showToast(Toast.makeError("Your session has expired. Please log in again."))
|
||||
}
|
||||
return throwError(error)
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue