diff --git a/backend/src/main/java/com/openisle/service/PushNotificationService.java b/backend/src/main/java/com/openisle/service/PushNotificationService.java index 8f9336e2d..f21d89ff8 100644 --- a/backend/src/main/java/com/openisle/service/PushNotificationService.java +++ b/backend/src/main/java/com/openisle/service/PushNotificationService.java @@ -23,14 +23,22 @@ public class PushNotificationService { private final PushService pushService; public PushNotificationService(PushSubscriptionRepository subscriptionRepository, - @Value("${app.webpush.public-key}") String publicKey, - @Value("${app.webpush.private-key}") String privateKey) throws GeneralSecurityException { + @Value("${app.webpush.public-key:}") String publicKey, + @Value("${app.webpush.private-key:}") String privateKey) throws GeneralSecurityException { this.subscriptionRepository = subscriptionRepository; - Security.addProvider(new BouncyCastleProvider()); - this.pushService = new PushService(publicKey, privateKey); + if (publicKey != null && !publicKey.isBlank() && privateKey != null && !privateKey.isBlank()) { + Security.addProvider(new BouncyCastleProvider()); + this.pushService = new PushService(publicKey, privateKey); + } else { + this.pushService = null; + } } public void sendNotification(User user, String payload) { + if (pushService == null) { + log.warn("Push notifications are disabled because VAPID keys are not configured."); + return; + } List subs = subscriptionRepository.findByUser(user); for (PushSubscription sub : subs) { try {