HeHeedza

Why does Supabase login fail with "TypeError: Failed to fetch" on my live site?

Last reviewed

Short answer

"Failed to fetch" means the browser never got a usable response, so it's not a wrong-password error. Open DevTools → Network and click the failed request. undefined in the URL means a missing env var. Can't resolve the host means a wrong or deleted project. A CORS error means an Edge Function. A paused project or a network blocking supabase.co covers most of the rest.

Why this happens

Supabase's JavaScript client uses fetch. When the request can't complete at all (DNS failure, blocked connection, CORS rejection, invalid URL), the browser throws a generic TypeError: Failed to fetch and hides the real reason from your code. The Network tab still shows it. The usual causes, roughly in order:

  1. The env var is missing in production. The request goes to undefined/auth/v1/token, or to your own domain.
  2. Wrong project URL, for example a typo, an old project, or a deleted project. Shows as ERR_NAME_NOT_RESOLVED.
  3. The project is paused (Free plan inactivity).
  4. CORS on an Edge Function your login flow calls, often hidden behind a 500 error.
  5. Something on the user's side blocks it: an ad or privacy extension, a company firewall, or a network that blocks *.supabase.co.

How to fix it, step by step

1. Find the failing request. On the live site, open DevTools → Network, tick Preserve log, and try to log in. Click the red request and read its URL and Status.

You seeMeaningFix
URL contains undefined or points at your own domainEnv var missing at buildAdd VITE_SUPABASE_URL / NEXT_PUBLIC_SUPABASE_URL and the key to Production, then rebuild
ERR_NAME_NOT_RESOLVEDWrong or old project refCopy the URL from Supabase Connect, then rebuild
CORS error on /functions/v1/...Edge Function preflight or error responseAdd CORS headers to every response (see the related guide)
ERR_BLOCKED_BY_CLIENTBrowser extensionTest without extensions. Consider a Supabase custom domain
Times out or fails only on one networkNetwork or firewall blockTest on mobile data. Consider a custom domain

2. Check the project is up. Open the Supabase dashboard. If it says Paused, click Resume project. You can also test from a terminal:

curl -i "https://<project-ref>.supabase.co/auth/v1/health" -H "apikey: <publishable-or-anon-key>"

A 200 with a small JSON body means Auth is reachable.

3. Log what the client was built with. Temporarily add this to the client file to confirm the values that shipped. The URL is public, but don't log the key in full:

console.info('Supabase URL in this build:', import.meta.env.VITE_SUPABASE_URL);

4. Avoid mixed content. Your site and the Supabase URL must both be https://.

5. Retest in a private window, with no extensions, on the live domain.

Fix prompt for your AI builder

Paste this into Lovable, Bolt, Cursor, Claude, ChatGPT, Replit, v0 or whichever tool you build with. Replace the bracketed parts first.

Fix prompt
Login on https://yourdomain.com fails with "TypeError: Failed to fetch". In the Network tab, the failing request URL is: [paste] and the status/error is: [paste].
Please:
1. Make sure our Supabase client reads the URL and publishable/anon key from the correct build-time env vars, and throws a clear error if they're missing.
2. If the failing request is an Edge Function, make it answer OPTIONS with CORS headers and include the CORS headers on every response, including errors.
3. Show a friendly "Can't reach the server, please try again" message instead of a blank failure.
Don't change the login design, and don't put any secret key in front-end code.

How to catch this next time

Several of these causes (a missing env var, a renamed project, a crashed client) take down the page itself, not just the login button.

Heedza opens your live landing, signup and login pages in a real browser on a schedule. It checks that each loads and that the email field is visible, and emails you a screenshot and a fix prompt when one doesn't. It doesn't submit your login form, so a request that fails only on submit still needs a manual test after deploys. Run the free scan on your live URL.

Questions

Is "Failed to fetch" a wrong password?

No. A wrong password returns a normal error response such as "Invalid login credentials". Failed to fetch means the request didn't complete at all.

Why does it work for me but not for some users?

Their browser extensions or network may block supabase.co. A Supabase custom domain on your own domain can help in those cases.

Can a paused Supabase project cause this?

Yes. Free-plan projects can be paused after low activity. Resume it in the dashboard, and see the guide on preventing pauses.

Sources