From 2be5a75064cf2ae64c0233312a87c5fca184c5fe Mon Sep 17 00:00:00 2001 From: dylan Date: Fri, 31 Jan 2025 11:38:26 +0100 Subject: [PATCH] Update API client and request interceptor --- src/app/interceptors/request.interceptor.ts | 7 ++++++- src/gen/model/patchOperation.ts | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/gen/model/patchOperation.ts diff --git a/src/app/interceptors/request.interceptor.ts b/src/app/interceptors/request.interceptor.ts index c9c2233..324de9a 100644 --- a/src/app/interceptors/request.interceptor.ts +++ b/src/app/interceptors/request.interceptor.ts @@ -2,15 +2,20 @@ import {Injectable} from '@angular/core'; import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest,} from '@angular/common/http'; import {Observable} from 'rxjs'; import {AuthService} from '../services/auth.service'; +import {Router} from '@angular/router'; @Injectable() export class RequestInterceptor implements HttpInterceptor { - constructor(private authService: AuthService) { + constructor(private authService: AuthService, private router: Router) { } intercept(req: HttpRequest, next: HttpHandler): Observable> { const authToken = this.authService.getToken() || ""; + if (authToken == "") { + this.router.navigate(["/login"]); + } + const newReq = req.clone({ headers: req.headers.set("Authorization", `Bearer ${authToken}`), }); diff --git a/src/gen/model/patchOperation.ts b/src/gen/model/patchOperation.ts new file mode 100644 index 0000000..0a0ab61 --- /dev/null +++ b/src/gen/model/patchOperation.ts @@ -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; +} +