Implement appeal form flow with dynamic pages, integrate punishment selection, and add username retrieval logic. Update API schema and enhance auth.service for username handling.

This commit is contained in:
2025-08-05 23:11:38 +02:00
parent 737b26a6c7
commit ae1e972438
8 changed files with 229 additions and 40 deletions
+29 -1
View File
@@ -1,4 +1,4 @@
import {Injectable} from '@angular/core';
import {Injectable, signal} from '@angular/core';
import {LoginService} from '@api';
import {BehaviorSubject, Observable, throwError} from 'rxjs';
import {catchError, tap} from 'rxjs/operators';
@@ -17,6 +17,8 @@ export class AuthService {
private userClaimsSubject = new BehaviorSubject<JwtClaims | null>(null);
public userClaims$ = this.userClaimsSubject.asObservable();
private jwtHelper = new JwtHelperService();
private _username = signal<string | null>(environment.defaultAuthStatus ? 'akastijn' : null);
public readonly username = this._username.asReadonly();
constructor(
private loginService: LoginService,
@@ -34,6 +36,8 @@ export class AuthService {
tap(jwt => {
this.saveJwt(jwt);
this.isAuthenticatedSubject.next(true);
this.reloadUsername();
}),
catchError(error => {
this.snackBar.open('Login failed', '', {duration: 2000});
@@ -42,6 +46,17 @@ export class AuthService {
);
}
private reloadUsername() {
this.loginService.getUsername().pipe(
tap(username => {
this._username.set(username.username);
}),
catchError(error => {
return throwError(() => error);
})
)
}
/**
* Log the user out by removing the JWT
*/
@@ -49,6 +64,7 @@ export class AuthService {
localStorage.removeItem('jwt');
this.isAuthenticatedSubject.next(false);
this.userClaimsSubject.next(null);
this._username.set(null);
}
/**
@@ -68,6 +84,7 @@ export class AuthService {
console.log("User claims: ", claims);
this.userClaimsSubject.next(claims);
this.isAuthenticatedSubject.next(true);
this.reloadUsername();
return true;
} catch (e) {
this.logout();
@@ -113,4 +130,15 @@ export class AuthService {
const userAuthorizations = this.getUserAuthorizations();
return requiredAuthorizations.some(auth => userAuthorizations.includes(auth));
}
public getUuid(): string | null {
if (environment.defaultAuthStatus) {
return '55e46bc3-2a29-4c53-850f-dbd944dc5c5f';
}
const jwtClaims = this.userClaimsSubject.getValue();
if (jwtClaims === null) {
return null;
}
return jwtClaims.sub ?? null;
}
}