From 4d9bb62907b0fd5e8e21a65df46c030d585be7a5 Mon Sep 17 00:00:00 2001 From: AIIrondev Date: Wed, 29 Jul 2026 11:15:57 +0200 Subject: [PATCH] Fix of the notification subscription --- Web/static/js/push-notifications.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Web/static/js/push-notifications.js b/Web/static/js/push-notifications.js index 9d734d3..b6aeb0f 100644 --- a/Web/static/js/push-notifications.js +++ b/Web/static/js/push-notifications.js @@ -25,7 +25,7 @@ class PushNotificationManager { * Initialize push notification system * Must be called after page load */ - async init() { + async init(providedKey = null) { if (!this.isSupported) { console.log('Push notifications not supported in this browser'); return false; @@ -49,11 +49,18 @@ class PushNotificationManager { } } - // Fetch VAPID public key from server + // Wenn der Key direkt aus dem Template übergeben wurde, nutze diesen (spart einen Request) + if (providedKey) { + this.vapidKey = providedKey; + return true; + } + + // Ansonsten: Fetch VAPID public key from server const keyResponse = await fetch('/api/push/vapid-key'); if (keyResponse.ok) { const keyData = await keyResponse.json(); - this.vapidKey = keyData.vapid_key; + // WICHTIG: Muss exakt mit dem Python-JSON-Key übereinstimmen! + this.vapidKey = keyData.publicKey; } else { console.warn('Failed to fetch VAPID key'); return false;