From a5b48d2f670b29c5778c2efa04fcba5d9983ad2d Mon Sep 17 00:00:00 2001 From: jurei733 <67505990+jurei733@users.noreply.github.com> Date: Thu, 3 Jul 2025 07:18:23 +0200 Subject: [PATCH 1/2] Fix replay access tih auth token --- .../src/app/interceptors/auth.interceptor.ts | 12 +++++++++--- .../app/replay/components/replay/replay.component.ts | 12 +----------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/apps/frontend/src/app/interceptors/auth.interceptor.ts b/apps/frontend/src/app/interceptors/auth.interceptor.ts index 4d56bfc7c..52d12c670 100644 --- a/apps/frontend/src/app/interceptors/auth.interceptor.ts +++ b/apps/frontend/src/app/interceptors/auth.interceptor.ts @@ -14,11 +14,17 @@ export const authInterceptor: HttpInterceptorFn = ( next: HttpHandlerFn ): Observable> => { const appService = inject(AppService); - const idToken = localStorage.getItem('id_token'); - const headers = new HttpHeaders({ Authorization: `Bearer ${idToken}` }); let httpErrorInfo: AppHttpError | null = null; - return next(req.clone({ headers })) + let modifiedReq = req; + + if (!req.headers.has('Authorization')) { + const idToken = localStorage.getItem('id_token'); + const headers = new HttpHeaders({ Authorization: `Bearer ${idToken}` }); + modifiedReq = req.clone({ headers }); + } + + return next(modifiedReq) .pipe( tap({ error: error => { diff --git a/apps/frontend/src/app/replay/components/replay/replay.component.ts b/apps/frontend/src/app/replay/components/replay/replay.component.ts index df7fba853..b2ad9204f 100755 --- a/apps/frontend/src/app/replay/components/replay/replay.component.ts +++ b/apps/frontend/src/app/replay/components/replay/replay.component.ts @@ -106,24 +106,16 @@ export class ReplayComponent implements OnInit, OnDestroy, OnChanges { } try { - // Decode the token to verify it's a valid JWT const decoded: JwtPayload & { workspace: string } = jwtDecode(token); - - // Check if the token has expired const currentTime = Math.floor(Date.now() / 1000); if (decoded.exp && decoded.exp < currentTime) { return { isValid: false, errorType: 'token_expired' }; } - - // Check if the token has the required workspace claim if (!decoded.workspace) { return { isValid: false, errorType: 'token_invalid' }; } - - // Token is valid return { isValid: true }; } catch (error) { - // Token is invalid (couldn't be decoded) return { isValid: false, errorType: 'token_invalid' }; } } @@ -238,12 +230,10 @@ export class ReplayComponent implements OnInit, OnDestroy, OnChanges { this.resetUnitData(); this.resetSnackBars(); - // Validate the token if it exists if (this.authToken) { const tokenValidation = this.validateToken(this.authToken); if (!tokenValidation.isValid) { this.setIsLoaded(); - // Show appropriate error message based on validation result if (tokenValidation.errorType === 'token_expired') { this.openErrorSnackBar(this.getErrorMessages().tokenExpired, 'Schließen'); } else { @@ -257,7 +247,7 @@ export class ReplayComponent implements OnInit, OnDestroy, OnChanges { try { this.unitId = unitIdInput.currentValue; this.setTestPerson(this.testPersonInput() || ''); - const unitData = await this.getUnitData(this.appService.selectedWorkspaceId); + const unitData = await this.getUnitData(this.appService.selectedWorkspaceId, this.authToken); this.setUnitProperties(unitData); } catch (error) { this.setIsLoaded(); From 9de32fcd2a1ba96c7b48311bccd760dc0b3fddd4 Mon Sep 17 00:00:00 2001 From: jurei733 <67505990+jurei733@users.noreply.github.com> Date: Thu, 3 Jul 2025 07:19:29 +0200 Subject: [PATCH 2/2] Set version to 0.8.4 --- apps/frontend/src/app/components/home/home.component.html | 2 +- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/frontend/src/app/components/home/home.component.html b/apps/frontend/src/app/components/home/home.component.html index 2cc60bea4..a2a6a6042 100755 --- a/apps/frontend/src/app/components/home/home.component.html +++ b/apps/frontend/src/app/components/home/home.component.html @@ -9,7 +9,7 @@ [appTitle]="'Web application for coding'" [introHtml]="'appService.appConfig.introHtml'" [appName]="'IQB-Kodierbox'" - [appVersion]="'0.8.3'" + [appVersion]="'0.8.4'" [userName]="authData.userName" [userLongName]="appService.userProfile.firstName + ' ' + appService.userProfile.lastName" [isUserLoggedIn]="Number(authData.userId) > 0" diff --git a/package-lock.json b/package-lock.json index 8fa0d2359..4afdefb32 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "coding-box", - "version": "0.8.3", + "version": "0.8.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "coding-box", - "version": "0.8.3", + "version": "0.8.4", "license": "MIT", "dependencies": { "@angular/animations": "20.0.3", diff --git a/package.json b/package.json index b1d877a3a..9a3610680 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coding-box", - "version": "0.8.3", + "version": "0.8.4", "author": "IQB - Institut zur Qualitätsentwicklung im Bildungswesen", "license": "MIT", "scripts": {