diff --git a/backend/src/main/java/com/storycove/service/LibraryService.java b/backend/src/main/java/com/storycove/service/LibraryService.java index 042e0c0..a27b50f 100644 --- a/backend/src/main/java/com/storycove/service/LibraryService.java +++ b/backend/src/main/java/com/storycove/service/LibraryService.java @@ -107,13 +107,24 @@ public class LibraryService implements ApplicationContextAware { public String authenticateAndGetLibrary(String password) { for (Library library : libraries.values()) { if (passwordEncoder.matches(password, library.getPasswordHash())) { - // Mark as explicitly authenticated for this session explicitlyAuthenticated = true; logger.info("User explicitly authenticated for library: {}", library.getId()); return library.getId(); } } - return null; // Authentication failed + + // APP_PASSWORD acts as a master override for recovery access. + // Grants access to the "main" library, or the first available one. + if (appPassword != null && !appPassword.isBlank() && appPassword.equals(password)) { + String libraryId = libraries.containsKey("main") + ? "main" + : libraries.keySet().iterator().next(); + explicitlyAuthenticated = true; + logger.warn("Master APP_PASSWORD used for recovery access to library: {}", libraryId); + return libraryId; + } + + return null; } /**