Update API client and request interceptor

This commit is contained in:
2025-01-31 11:38:26 +01:00
parent 28e370a0be
commit 2be5a75064
2 changed files with 23 additions and 1 deletions

View File

@ -2,15 +2,20 @@ import {Injectable} from '@angular/core';
import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest,} from '@angular/common/http'; import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest,} from '@angular/common/http';
import {Observable} from 'rxjs'; import {Observable} from 'rxjs';
import {AuthService} from '../services/auth.service'; import {AuthService} from '../services/auth.service';
import {Router} from '@angular/router';
@Injectable() @Injectable()
export class RequestInterceptor implements HttpInterceptor { export class RequestInterceptor implements HttpInterceptor {
constructor(private authService: AuthService) { constructor(private authService: AuthService, private router: Router) {
} }
intercept(req: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> { intercept(req: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
const authToken = this.authService.getToken() || ""; const authToken = this.authService.getToken() || "";
if (authToken == "") {
this.router.navigate(["/login"]);
}
const newReq = req.clone({ const newReq = req.clone({
headers: req.headers.set("Authorization", `Bearer ${authToken}`), headers: req.headers.set("Authorization", `Bearer ${authToken}`),
}); });

View File

@ -0,0 +1,17 @@
/**
* swisssign-challenge - dlmw
*
* Contact: dylan@dlmw.ch
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
export interface PatchOperation {
op: string;
path: string;
value: string;
}