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) {