Skip to content

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

Closed

Description

@maxwowo

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

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:

  • Java: openjdk 11.0.19 2023-04-18 LTS
  • Node: v16.20.2
  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

Screen.Recording.2023-10-16.at.7.23.23.pm.mov

System information

  • OS: macOS Sonoma 14.0
  • Browser (if applies) N/A
  • Version of supabase-js: 2.38.1
  • Version of Node.js: v16.20.2

Additional context

Add any other context about the problem here.

Activity

  1. added
    bug
    on Oct 16, 2023
  2. Killbyfire commented on Oct 17, 2023

    @Killbyfire

    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.

  3. atanaskanchev commented on Oct 19, 2023

    @atanaskanchev

    +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

  4. atanaskanchev commented on Oct 19, 2023

    @atanaskanchev

    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
    
  5. atanaskanchev commented on Oct 19, 2023

    @atanaskanchev

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

  6. atanaskanchev commented on Oct 19, 2023

    @atanaskanchev

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

  7. maxwowo commented on Oct 22, 2023

    @maxwowo
    Author

    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

  8. caseydierking commented on Feb 25, 2024

    @caseydierking

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

  9. carodej commented on Feb 26, 2024

    @carodej

    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

  10. caseydierking commented on Feb 28, 2024

    @caseydierking

    @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.

  11. atanaskanchev commented on Feb 29, 2024

    @atanaskanchev

    @caseydierking this solved it for me:

    • app.config.ts
     extra: {
        ...
      plugins: [
        ...
        [
          'expo-build-properties',
          {
            android: {
              usesCleartextTraffic: true
            }
          }
        ]
      ],
    
    • EXPO_PUBLIC_SUPABASE_URL=http://192.168.1.110:54321
  12. caseydierking commented on Mar 2, 2024

    @caseydierking

    @atanaskanchev That worked. Thanks!

  13. Teegreat commented on Mar 30, 2024

    @Teegreat

    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!

  14. TARishabh commented on Apr 7, 2024

    @TARishabh

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

  15. BigDrems commented on Jun 21, 2024

    @BigDrems

    How did you change your url?

  16. 2 remaining items

  17. blwinters commented on Sep 9, 2024

    @blwinters

    Changing the supabaseUrl from http://127.0.0.1:54321/ to http://10.0.2.2:54321/ fixed it for Android, but then iOS got the Network request failed error. So seems like you need to either use conditional logic that checks the platform, like Platform.select(...) and return the appropriate url, or read the expoConfig.hostUri as mentioned by @JacobJaffe.

    I went with the expoConfig approach. Also, it looks like they fixed the types on that so no need for casting to unknown.

  18. Mvrs commented on Oct 3, 2024

    @Mvrs

    Here's my solution:

    import Constants from "expo-constants";
    
    // Types on this are wrong. This exists, and `host` does not.
    const origin = (
      Constants?.expoConfig as unknown as { hostUri?: string }
    )?.hostUri
      ?.split(":")
      .shift();
    
    if (!origin) throw new Error("Could not determine origin");
    
    const supabaseUrl = `http://${origin}:54321`;

    This is very similar to what is typically needed to connect to local Firebase projects.

    As a sanity check, I'd recommend logging hostUri, and try going to hostUri:54323 in your phone's browser. That should show the Supabase dashboard.

    FWIW, this should apply for both ios and android. This is JS issue, not a native issue

    Thank you! This worked 🔥

  19. pammu453 commented on Nov 7, 2024

    @pammu453

    image
    Error while SignUp

    const handleSubmite = async () => {
        const username = form.username.trim()
        const email = form.email.trim()
        const password = form.password.trim()
    
        if (!username || !email || !password) {
            Alert.alert("Incomplete Information", "Please fill in all required fields to continue.")
            return
        }
    
        console.log(form)
    
        setLoading(true)
        const { data, error } = await supabase.auth.signUp({
            email,
            password,
        })
    
        console.log("Session", data)
        console.log("Error", error)
    
        setLoading(false)
    }
    
    supabase.js
    const supabaseUrl = 'https://kkrmnwoeearnagfdqpyi.supabase.com'
    

    image

    Please some one help me
    @caseydierking @blwinters @Mvrs @carodej

  20. pammu453 commented on Nov 7, 2024

    @pammu453

    After spending two days troubleshooting this issue, I found that the root cause was related to the initial project location setting in Supabase. My original project was created with Singapore as the region, while I am based in India.

    To resolve this, I created a new Supabase project and selected India as the region. This adjustment immediately resolved the issue.

    Recommendation: When creating a new Supabase project, make sure to select a region close to your actual location to avoid connectivity issues.
    image

  21. angelroma commented on Feb 8, 2025

    @angelroma

    In my case, this happened because I was using the remote Supabase instance, but I wanted to switch to a local one for convenience. When I did that, I encountered an error. To fix it, I cleared the cache from the Expo app, and it worked.

    For Android, I used:
    EXPO_PUBLIC_SUPABASE_URL=http://10.0.2.2:54321 instead.

  22. raozhaizhu commented on Jun 28, 2025

    @raozhaizhu

    @caseydierking this solved it for me:

    • app.config.ts
     extra: {
        ...
      plugins: [
        ...
        [
          'expo-build-properties',
          {
            android: {
              usesCleartextTraffic: true
            }
          }
        ]
      ],
    
    • EXPO_PUBLIC_SUPABASE_URL=http://192.168.1.110:54321

    grazie

  23. added
    has workaround
    on Nov 3, 2025
  24. SharmaVrishab commented on Feb 23, 2026

    @SharmaVrishab

    i am seeing the same error i am using supabase for authentication

  25. mandarini commented on Feb 24, 2026

    @mandarini
    Contributor

    @SharmaVrishab Does the workaround work for you?

  26. added
    temp - locks
    on Apr 29, 2026
  27. mandarini commented on May 26, 2026

    @mandarini
    Contributor

    Here is the refactor: #2392

    Published under 2.107.0-beta.1.

    Instructions on how to migrate are here.

    Non breaking change, backwards compatible. Please let me know if you try it out, we're trying to evaluate this before publishing.

    @maxwowo @SharmaVrishab

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughas workaroundtemp - locks

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions