From c62606b09df41b0a549de87663bbfaf696a3ee65 Mon Sep 17 00:00:00 2001 From: Hermes Date: Tue, 18 Aug 2026 12:32:26 +0200 Subject: [PATCH] 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) --- src/hooks/usePushNotifications.js | 40 ++++++++----------------------- 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/src/hooks/usePushNotifications.js b/src/hooks/usePushNotifications.js index af58f13..ec32c62 100644 --- a/src/hooks/usePushNotifications.js +++ b/src/hooks/usePushNotifications.js @@ -1,5 +1,5 @@ import React from "react"; -import { supabase, hasSupabaseConfig } from "../supabaseClient"; +import { hasSupabaseConfig } from "../supabaseClient"; 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(); - if (!session?.access_token) return null; - - const res = await fetch(`${supabase.supabaseUrl}/functions/v1/subscribe-push`, { - method: "POST", - headers: { - "Content-Type": "application/json", - 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; - } + // NOTE (2026-08): the server-side push_subscriptions table is keyed by + // phone_normalized and is used by the CLIENT flow (PushSubscriptionBanner → + // functions/v1/push-subscribe). Staff users authenticate by email and have no + // phone in the session, so there is no working server endpoint for staff push + // subscriptions — the old code called /functions/v1/subscribe-push which does + // not exist (500 InvalidWorkerCreation). We keep the local browser + // subscription only; server-side push for staff remains out of scope. return subscription; } @@ -59,20 +50,9 @@ export async function unsubscribeUserFromPush() { const subscription = await registration.pushManager.getSubscription(); 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(); - - 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) {