save having new services push

Anonymous
plain_text
02/18/2026 3:33 AM
2.1 KB
9
Indexable
import { supabase } from '@/constants/supabase';

interface SendPushOptions {
  userId: string;
  title: string;
  body: string;
  data?: Record<string, unknown>;
}

export async function sendPushNotificationToUser({ userId, title, body, data }: SendPushOptions): Promise<{ success: boolean; error?: string }> {
  try {
    console.log('[PushNotification] Sending to userId:', userId, { title, body });
    const { error } = await supabase.functions.invoke('send-push-notification', {
      body: { userId, title, body, data: data ?? {} },
    });

    if (error) {
      console.error('[PushNotification] Error sending:', error);
      return { success: false, error: String(error) };
    }
    console.log('[PushNotification] Sent successfully to:', userId);
    return { success: true };
  } catch (err) {
    console.error('[PushNotification] Unexpected error:', err);
    return { success: false, error: String(err) };
  }
}

export async function sendPushNotification({ userId, title, body, data }: SendPushOptions): Promise<void> {
  try {
    console.log('[PushNotification] Sending to userId:', userId, { title, body });
    const { error } = await supabase.functions.invoke('send-push-notification', {
      body: { userId, title, body, data: data ?? {} },
    });

    if (error) {
      console.error('[PushNotification] Error sending:', error);
    } else {
      console.log('[PushNotification] Sent successfully to:', userId);
    }
  } catch (err) {
    console.error('[PushNotification] Unexpected error:', err);
  }
}

Editor is loading...
Leave a Comment