From 7368fa77aedf2b8b5ebef10bc1dead24580cbaa9 Mon Sep 17 00:00:00 2001 From: Tim <135014430+nagisa77@users.noreply.github.com> Date: Mon, 4 Aug 2025 21:47:59 +0800 Subject: [PATCH] Allow missing push notification keys --- .../service/PushNotificationService.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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 {