Fix of the notification subscription

This commit is contained in:
2026-07-29 11:15:57 +02:00
parent 8251cd9bfd
commit 4d9bb62907
+10 -3
View File
@@ -25,7 +25,7 @@ class PushNotificationManager {
* Initialize push notification system * Initialize push notification system
* Must be called after page load * Must be called after page load
*/ */
async init() { async init(providedKey = null) {
if (!this.isSupported) { if (!this.isSupported) {
console.log('Push notifications not supported in this browser'); console.log('Push notifications not supported in this browser');
return false; 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'); const keyResponse = await fetch('/api/push/vapid-key');
if (keyResponse.ok) { if (keyResponse.ok) {
const keyData = await keyResponse.json(); const keyData = await keyResponse.json();
this.vapidKey = keyData.vapid_key; // WICHTIG: Muss exakt mit dem Python-JSON-Key übereinstimmen!
this.vapidKey = keyData.publicKey;
} else { } else {
console.warn('Failed to fetch VAPID key'); console.warn('Failed to fetch VAPID key');
return false; return false;