fix(push): remove staff calls to non-existent subscribe-push/unsubscribe-push edge functions (500 InvalidWorkerCreation)

- staff hook called /functions/v1/subscribe-push which does not exist on the
  server (functions are named push-subscribe/push-unsubscribe and are keyed by
  phone_normalized for the CLIENT flow only; push_subscriptions has no user_id)
- keep local browser PushManager subscription; drop broken server round-trips
- client PushSubscriptionBanner flow untouched (uses correct endpoint)
This commit is contained in:
Hermes 2026-08-18 12:32:26 +02:00
parent 7a76c0a6c0
commit c62606b09d
1 changed files with 10 additions and 30 deletions

View File

@ -1,5 +1,5 @@
import React from "react"; import React from "react";
import { supabase, hasSupabaseConfig } from "../supabaseClient"; import { hasSupabaseConfig } from "../supabaseClient";
const VAPID_PUBLIC_KEY = "BBHRiMfIGQf3EjnnPQ6QS-jS2oset-YMmufJSvw-0a974ULxLaxQqZkfB0ldz-tqH6B9WAIh9Et86i0ezjuedmU"; const VAPID_PUBLIC_KEY = "BBHRiMfIGQf3EjnnPQ6QS-jS2oset-YMmufJSvw-0a974ULxLaxQqZkfB0ldz-tqH6B9WAIh9Et86i0ezjuedmU";
@ -32,22 +32,13 @@ export async function subscribeUserToPush(userId) {
} }
} }
const { data: { session } } = await supabase.auth.getSession(); // NOTE (2026-08): the server-side push_subscriptions table is keyed by
if (!session?.access_token) return null; // phone_normalized and is used by the CLIENT flow (PushSubscriptionBanner →
// functions/v1/push-subscribe). Staff users authenticate by email and have no
const res = await fetch(`${supabase.supabaseUrl}/functions/v1/subscribe-push`, { // phone in the session, so there is no working server endpoint for staff push
method: "POST", // subscriptions — the old code called /functions/v1/subscribe-push which does
headers: { // not exist (500 InvalidWorkerCreation). We keep the local browser
"Content-Type": "application/json", // subscription only; server-side push for staff remains out of scope.
Authorization: `Bearer ${session.access_token}`,
},
body: JSON.stringify({ subscription: subscription.toJSON() }),
});
if (!res.ok) {
console.error("Failed to save push subscription:", await res.text());
return null;
}
return subscription; return subscription;
} }
@ -59,20 +50,9 @@ export async function unsubscribeUserFromPush() {
const subscription = await registration.pushManager.getSubscription(); const subscription = await registration.pushManager.getSubscription();
if (!subscription) return; if (!subscription) return;
const endpoint = subscription.endpoint; // NOTE (2026-08): no server-side unsubscribe endpoint for staff (see
// subscribeUserToPush above). Local browser subscription is removed only.
await subscription.unsubscribe(); await subscription.unsubscribe();
const { data: { session } } = await supabase.auth.getSession();
if (session?.access_token) {
await fetch(`${supabase.supabaseUrl}/functions/v1/unsubscribe-push`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${session.access_token}`,
},
body: JSON.stringify({ endpoint }),
});
}
} }
export function usePushNotifications(userId) { export function usePushNotifications(userId) {