From 82f2f4f55767758f2601f9d898a5c2b66a005d5f Mon Sep 17 00:00:00 2001 From: James Ward Date: Sat, 26 Sep 2026 13:20:22 -0400 Subject: [PATCH] fix(api): allow logout with user `anonymousUser` (#2764) --- .../org/booklore/config/security/service/LogoutService.java | 2 +- .../org/booklore/config/security/service/LogoutServiceTest.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/src/main/java/org/booklore/config/security/service/LogoutService.java b/backend/src/main/java/org/booklore/config/security/service/LogoutService.java index 53674ff01..64afbc9b1 100644 --- a/backend/src/main/java/org/booklore/config/security/service/LogoutService.java +++ b/backend/src/main/java/org/booklore/config/security/service/LogoutService.java @@ -52,7 +52,7 @@ public class LogoutService { } private BookLoreUserEntity resolveUser(Authentication auth, String refreshToken) { - if (auth != null && auth.isAuthenticated() && !"anonymousUser".equals(auth.getPrincipal())) { + if (auth != null && auth.isAuthenticated()) { var bookLoreUser = authenticationService.getAuthenticatedUser(); return userRepository.findByUsername(bookLoreUser.getUsername()) .orElseThrow(() -> ApiError.GENERIC_UNAUTHORIZED.createException("User not found")); diff --git a/backend/src/test/java/org/booklore/config/security/service/LogoutServiceTest.java b/backend/src/test/java/org/booklore/config/security/service/LogoutServiceTest.java index 998a9422f..788ce0038 100644 --- a/backend/src/test/java/org/booklore/config/security/service/LogoutServiceTest.java +++ b/backend/src/test/java/org/booklore/config/security/service/LogoutServiceTest.java @@ -274,7 +274,6 @@ class LogoutServiceTest { private Authentication mockAuth() { var auth = mock(Authentication.class); when(auth.isAuthenticated()).thenReturn(true); - when(auth.getPrincipal()).thenReturn("not-anonymous"); return auth; }