supabase / supabase-js

An isomorphic Javascript client for Supabase. Query your Supabase database, subscribe to realtime events, upload and download files, browse typescript examples, invoke postgres functions via rpc, invoke supabase edge functions, query pgvector.
https://supabase.com
MIT License
2.86k stars 220 forks source link

TypeError: Network request failed on sign up / sign in on Android #879

Open maxwowo opened 7 months ago

maxwowo commented 7 months ago

Bug report

Describe the bug

Signing in or up on Android emulator locally results in TypeError: Network request failed. This error only shows up on the Android emulator and not the iOS one

To Reproduce

Minimal reproducible example: https://github.com/maxwowo/sbrepro

Environment:

  1. Clone repo
  2. supabase start
  3. yarn install
  4. yarn android
  5. Click on either Sign up or Sign in

Expected behavior

Should sign up or sign in without error

Screenshots

https://github.com/supabase/supabase-js/assets/40416283/b85f24b7-3c1f-4f0a-ad56-484ce0fd4964

System information

Additional context

Add any other context about the problem here.

Killbyfire commented 7 months ago

Started happening to me too once locally running supabase, since last year i changed nothing but only running supabase locally instead of having it hosted online and it keeps giving me network request failed aswell.

atanaskanchev commented 7 months ago

+1 on this. I also get the Network request failed on Android Emulator and additionally, the session is not available after login. No such issues with ios simulator

atanaskanchev commented 7 months ago

Here some debug logging from auth

export const supabase = createClient<Database>(config.supabaseUrl, config.supabaseAnonKey, {
  auth: {
   storage: AsyncStorage,
    autoRefreshToken: true,
    persistSession: true,
    detectSessionInUrl: false,
    debug: true
  }
})
 ERROR  [TypeError: Network request failed]
 LOG  {"error": null, "isLoading": false, "session": null}
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:46:27.628Z #_autoRefreshTokenTick() begin
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:46:27.630Z #_acquireLock begin 0
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:46:27.631Z #_acquireLock lock acquired for storage key sb-localhost-auth-token
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:46:27.631Z #_useSession begin
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:46:27.631Z #__loadSession() begin
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:46:27.632Z #getSession() session from storage null
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:46:27.633Z #__loadSession() end
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:46:27.634Z #_autoRefreshTokenTick() no session
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:46:27.634Z #_useSession end
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:46:27.634Z #_autoRefreshTokenTick() end
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:46:27.634Z #_acquireLock lock released for storage key sb-localhost-auth-token
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:46:27.635Z #_acquireLock end
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:46:57.646Z #_autoRefreshTokenTick() begin
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:46:57.647Z #_acquireLock begin 0
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:46:57.647Z #_acquireLock lock acquired for storage key sb-localhost-auth-token
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:46:57.648Z #_useSession begin
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:46:57.648Z #__loadSession() begin
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:46:57.650Z #getSession() session from storage null
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:46:57.650Z #__loadSession() end
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:46:57.651Z #_autoRefreshTokenTick() no session
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:46:57.653Z #_useSession end
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:46:57.654Z #_autoRefreshTokenTick() end
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:46:57.654Z #_acquireLock lock released for storage key sb-localhost-auth-token
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:46:57.655Z #_acquireLock end
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:47:27.662Z #_autoRefreshTokenTick() begin
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:47:27.663Z #_acquireLock begin 0
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:47:27.664Z #_acquireLock lock acquired for storage key sb-localhost-auth-token
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:47:27.664Z #_useSession begin
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:47:27.664Z #__loadSession() begin
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:47:27.664Z #getSession() session from storage null
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:47:27.665Z #__loadSession() end
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:47:27.665Z #_autoRefreshTokenTick() no session
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:47:27.665Z #_useSession end
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:47:27.665Z #_autoRefreshTokenTick() end
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:47:27.665Z #_acquireLock lock released for storage key sb-localhost-auth-token
 LOG  GoTrueClient@0 (2.56.0) 2023-10-19T12:47:27.665Z #_acquireLock end
atanaskanchev commented 7 months ago

Tried downgrading to "@supabase/supabase-js": "2.33.2" but the issue is still there. I wonder if it's related to Sonoma

atanaskanchev commented 7 months ago

Will make a PlayStore build to see if this is only local and report back

maxwowo commented 6 months ago

I've since then switched to developing with Supabase Cloud. No such problems whatsoever. Haven't exceeded the limits on the free tier either so far. Would suggest the same if you've been blocked by this for a while

caseydierking commented 2 months ago

I'm running into this on Android Emulator and iOS on Expo Go. Anyone get around this other than using Supabase Cloud?

carodej commented 2 months ago

My problem was in supabase api url - instead of default I replaced it with http://10.0.2.2:54321 as your emulator does not work with http://127.0.0.1:54321.

The reason is that 10.0.2.2 points to your actual machine instead of some loopback service.

@caseydierking try this and let me know if it works for you

caseydierking commented 2 months ago

@carodej Unfortunately it did not work. Out of curiosity, I wondered if it was because of an http/https issue. So I tunneled it through ngrok and it worked. That is not a great long term solution though.

atanaskanchev commented 2 months ago

@caseydierking this solved it for me:

 extra: {
    ...
  plugins: [
    ...
    [
      'expo-build-properties',
      {
        android: {
          usesCleartextTraffic: true
        }
      }
    ]
  ],
caseydierking commented 2 months ago

@atanaskanchev That worked. Thanks!

Teegreat commented 1 month ago

My problem was in supabase api url - instead of default I replaced it with http://10.0.2.2:54321 as your emulator does not work with http://127.0.0.1:54321.

The reason is that 10.0.2.2 points to your actual machine instead of some loopback service.

@caseydierking try this and let me know if it works for you

This worked. Thank you!

TARishabh commented 1 month ago

changing the supabaseUrl from http://127.0.0.1:54321 to http://10.0.2.2:54321 worked for me.