Fix of the notification subscription
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user