supabase-js: TypeError: Network request failed on sign up / sign in on Android
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
- Clone repo
supabase startyarn installyarn android- Click on either
Sign uporSign 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
- 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.
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 5
- Comments: 22
Here’s my solution:
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 tohostUri:54323in 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
My problem was in supabase api url - instead of default I replaced it with
http://10.0.2.2:54321as your emulator does not work withhttp://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
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
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.
@caseydierking this solved it for me:
EXPO_PUBLIC_SUPABASE_URL=http://192.168.1.110:54321+1 on this. I also get the
Network request failedon Android Emulator and additionally, the session is not available after login. No such issues with ios simulatorI tried this, and the only thing that changed was I got the network error after 2 minutes of wait time.
But I got it working by tunneling it through Cloudflare, by which I got a HTTPS URL, not a permanent solution but fulfills the need for the moment.
changing the supabaseUrl from http://127.0.0.1:54321 to http://10.0.2.2:54321 worked for me.