Refactor logging in LoginController, simplify auth.service token validation, and remove debug logs from AppealComponent.

This commit is contained in:
akastijn 2025-08-05 23:22:12 +02:00
parent bdb38e5011
commit f67cb50f41
3 changed files with 18 additions and 18 deletions

View File

@ -93,6 +93,7 @@ public class LoginController implements LoginApi {
@Override @Override
public ResponseEntity<UsernameDto> getUsername() { public ResponseEntity<UsernameDto> getUsername() {
log.debug("Loading username for logged in user");
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null || !(authentication.getPrincipal() instanceof OAuth2ResourceServerProperties.Jwt)) { if (authentication == null || !(authentication.getPrincipal() instanceof OAuth2ResourceServerProperties.Jwt)) {
@ -103,13 +104,14 @@ public class LoginController implements LoginApi {
UUID uuid; UUID uuid;
try { try {
uuid = UUID.fromString(stringUuid); uuid = UUID.fromString(stringUuid);
log.debug("Loaded username for logged in user {}", uuid);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
return ResponseEntity.badRequest().build(); return ResponseEntity.badRequest().build();
} }
UsernameDto usernameDto = new UsernameDto(); UsernameDto usernameDto = new UsernameDto();
usernameDto.setUsername(getUsername(uuid)); usernameDto.setUsername(getUsername(uuid));
log.debug("Loaded username for logged in user {}", usernameDto.getUsername());
return ResponseEntity.ok(usernameDto); return ResponseEntity.ok(usernameDto);
} }

View File

@ -164,9 +164,7 @@ export class AppealComponent implements OnInit, AfterViewInit {
public nextPage() { public nextPage() {
if (this.currentPageIndex === this.totalPages.length - 1) { if (this.currentPageIndex === this.totalPages.length - 1) {
console.log('Adding page');
this.totalPages.push(this.currentPageIndex + 1); this.totalPages.push(this.currentPageIndex + 1);
console.log(this.totalPages);
} }
this.goToPage(this.currentPageIndex + 1); this.goToPage(this.currentPageIndex + 1);
} }

View File

@ -72,23 +72,23 @@ export class AuthService {
*/ */
public checkAuthStatus(): boolean { public checkAuthStatus(): boolean {
const jwt = this.getJwt(); const jwt = this.getJwt();
if (jwt) { if (!jwt) {
try { return false;
// Check if token is expired }
if (this.jwtHelper.isTokenExpired(jwt)) { try {
this.logout(); if (this.jwtHelper.isTokenExpired(jwt)) {
return false;
}
const claims = this.extractJwtClaims(jwt);
console.log("User claims: ", claims);
this.userClaimsSubject.next(claims);
this.isAuthenticatedSubject.next(true);
this.reloadUsername();
return true;
} catch (e) {
this.logout(); this.logout();
return false;
} }
const claims = this.extractJwtClaims(jwt);
console.log("User claims: ", claims);
this.userClaimsSubject.next(claims);
this.isAuthenticatedSubject.next(true);
this.reloadUsername();
return true;
} catch (e) {
this.logout();
} }
return false; return false;
} }