Unable to get valid response from Supabase local CLI through javascript client library

124 views Asked by At

I am trying to connect a react native app to a local Supabase development set up. I am doing so using the localhost API url and the provided anon key:

const supabaseUrl = 'http://localhost:54321'
const supabaseAnonKey = 'my anon key'

export const supabase = createClient(supabaseUrl, supabaseAnonKey, {
  auth: {
    storage: new LargeSecureStore(),
    autoRefreshToken: true,
    persistSession: true,
    detectSessionInUrl: false,
  },
});

However, when I try to make any requests to my local server, e.g. returning table information or signing up I get the error: 'TypeError: Network request failed'

const { data, error } = await supabase.from("test").select("*");
> 'TypeError: Network request failed'

Replacing the supabaseUrl and supabaseAnonKey with their values from my online project functions as usual. Making the same request through the terminal does return results.

curl 'http://localhost:54321/rest/v1/test' \
-H "apikey: my anon key" \
-H "Authorization: Bearer my anon key"

>[{"id":1,"created_at":"2023-10-19T09:31:05.307966+00:00"}]

Anyone know what the issue could potentially be?

1

There are 1 answers

0
supastuck On BEST ANSWER

Never mind - figured it out, as I was connecting through my phone on expo I needed to replace localhost with my local machine ip.