Skip to content
Merged

0.8.4 #173

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/frontend/src/app/components/home/home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 9 additions & 3 deletions apps/frontend/src/app/interceptors/auth.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ export const authInterceptor: HttpInterceptorFn = (
next: HttpHandlerFn
): Observable<HttpEvent<unknown>> => {
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 => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' };
}
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down