0

I'm trying to develop a local supabase edge function. I have followed the documentation and correctly installed and locally deployed the function.

I have a simple edge function that, when it receive a request, it fetches some data from the database:

import { createClient } from 'https://esm.sh/@supabase/[email protected]'

Deno.serve(async (req) => {
  try {
    const supabase = createClient(
      Deno.env.get('SUPABASE_URL') ?? '',
      Deno.env.get('SUPABASE_ANON_KEY') ?? '',
      { global: { headers: { Authorization: req.headers.get('Authorization')! } } }
    )
    // Fetch all websites from the 'websites' table
    const { data: websites, error } = await supabase
      .from('websites')
      .select('url')
      .limit(1)
    
    if (error) {
      console.log(error)
      throw error
    }

I use supabase function serve to test locally but, everytime I launch http://127.0.0.1:54321/functions/v1/<function-name> to test it I have the error

{"error":"relation \"public.<table_name>\" does not exist"}

I have also tried to change the SUPABASE_ANON_KEY with the SUPABASE_SERVICE_ROLE_KEY but same issue

The table public.<table_name> exist on my cloud instance of Supabase

I have also tried to disable RLS but still the same issue.

I have also tried to follow this simple example but it fails...

Running the SQL questy directly on Supabase cloud works SELECT <column_name> FROM public.<table_name>

I think there's some issue with the local edge function

1 Answer 1

1

In your code you are using Deno.env.get('SUPABASE_URL') which will call the local supabase url and not your cloud hosted one. You would need to set a .env file inside of your supabase/functions directory with the SUPABASE_URL to your cloud hosted endpoint for this to work with your cloud hosted supabase instance. Do note that you will also need to set the SUPABASE_ANON_KEY in your .env file to match that of the cloud hosted one too.

Sign up to request clarification or add additional context in comments.

1 Comment

I followed the same steps, and it always connects/starts to the local supabase instance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.