Has anyone managed to create an edge function in which there is a query on a table? I have this code:
import {
createClient
} from 'https://esm.sh/@supabase/[email protected]'
import { FunctionsHttpError, FunctionsRelayError, FunctionsFetchError } from '@supabase/supabase-js'
Deno.serve(async (req) => {
const authHeader = req.headers.get('Authorization')!
const supabase = createClient(
'MYSUPABASE URL', // URL de votre instance Supabase
'ANON_KEY', // Clé API anonyme
{
global: {
headers: {
Authorization: authHeader //authHeader = "Bearer XXXXXXXXX"
}
}
}
);
const payload = await req.json();
// Log the entire JSON payload
console.log("Received JSON payload:", JSON.stringify(payload, null, 2));
// Ensure that payload.record exists
if (payload.record) {
const title = payload.record.title || "Viibr";
const content = payload.record.content ;
const userId = payload.record.user_id;
const campaign = payload.record.campaign || "PushNotification";
const bigImage = payload.record['big-Image'] ;
let mess="MESSAGE";
const {data:dataUser, error } = await supabase.from('profiles').select('*').eq('user_id',userId).single();
console.log("Received from Supabase:", dataUser);
if (dataUser && dataUser.length > 0) {
mess = Data received: ${JSON.stringify(dataUser)}; // Utilisation de la donnée reçue
} else if (error) {
mess = Error: ${error.message}; // Utilisation du message d'erreur
} else {
mess = "No data received and no error reported.";
}
but in my test mess is always "No data received and no error reported.";
the select query doesn't do anything..