Supabase "TypeError: Failed to fetch": why login and queries fail before Supabase answers
By AI App Medic · Updated · Supabase · Auth · Networking · Lovable
A user taps Sign in, or a page tries to load its data, and nothing happens. The console shows one of these:
AuthRetryableFetchError: Failed to fetch
TypeError: Failed to fetch
{ message: "TypeError: Failed to fetch", details: "...", hint: "", code: "" }
The first comes from supabase-js auth calls such as signInWithPassword, signUp or a session refresh. The last is what a database query returns in error when you call supabase.from("table").select() and the request fails. In Safari the text is Load failed, and in Firefox it is NetworkError when attempting to fetch resource.
All of them mean the same thing: the browser's fetch() did not get a response the page was allowed to read. This is not a wrong password and not a row level security problem. Those come back as normal HTTP responses with a status and a JSON body. Looking at the supabase-js source, the auth client wraps any fetch that fails without a response in AuthRetryableFetchError with status 0, and the query client turns it into an error object whose message is the browser's own text. The message cannot tell you why it failed, because browsers hide network and CORS details from JavaScript on purpose. The Network tab can.
Step 1: read the failed request
Open the live site, press F12 (Cmd+Option+I on a Mac), open the Network tab and repeat the action. Click the red request to your Supabase address. For a password login it ends in /auth/v1/token?grant_type=password, for a query it starts with /rest/v1/, and for an Edge Function it starts with /functions/v1/. Then look at the Console for the matching red line. What you see points to a cause:
net::ERR_NAME_NOT_RESOLVED: the host name does not exist or is blocked by DNS. See causes 1 and 3.net::ERR_CONNECTION_REFUSEDonlocalhostor127.0.0.1: the live app is calling your local Supabase. See cause 1.Mixed Contentorblocked:mixed-content: the app callshttp://from anhttps://page. See cause 1.- Status
540: the project is paused. See cause 2. net::ERR_BLOCKED_BY_CLIENT: an extension in this browser blocked it. See cause 3.- "has been blocked by CORS policy": the server answered without the headers the browser needs. See cause 4.
- Status
(canceled)orNS_BINDING_ABORTED: your page cancelled its own request. See cause 5. - Status
502,503,504or52x: Supabase did answer, with a server or gateway error. See cause 6.
Cause 1: the live app calls the wrong address
This is the most common cause in AI-built apps. The code runs fine in the editor preview, and the deployed build points somewhere else. Look at the host in the failed request and compare it with the URL shown under Connect in your Supabase dashboard. It must be exactly https://YOUR_PROJECT_REF.supabase.co, or your custom domain if you set one. Things that go wrong:
- The project ref belongs to an old project. This happens after remixing a Lovable project, moving off a builder's managed backend, or creating a fresh Supabase project and forgetting one environment.
- The value is
http://localhost:54321orhttp://127.0.0.1:54321, the Supabase CLI's local stack, copied from.env.localinto production. - A typo, a trailing space or quotes pasted into the host's environment variable field.
- The URL starts with
http://. Browsers block plain HTTP requests from an HTTPS page.
Find where the client is created. In a Lovable project it is usually src/integrations/supabase/client.ts, in other Vite apps something like src/lib/supabase.ts:
import { createClient } from "@supabase/supabase-js";
const url = import.meta.env.VITE_SUPABASE_URL;
const key = import.meta.env.VITE_SUPABASE_ANON_KEY;
if (!url || !url.startsWith("https://")) {
throw new Error(`Bad VITE_SUPABASE_URL: ${url}`);
}
export const supabase = createClient(url, key);
The guard makes a broken build fail loudly on load instead of failing quietly on the first login. Then fix the value where the build runs: Vercel, Netlify or Cloudflare project settings. Vite and Next.js copy these variables into the JavaScript bundle when the site is built, so changing the setting does nothing until you redeploy. The Bolt env variables undefined on Netlify guide walks through this for Vite, and the Next.js env variables undefined on Vercel guide covers NEXT_PUBLIC_ names.
You can test the address from a terminal, outside any browser:
curl -i "https://YOUR_PROJECT_REF.supabase.co/auth/v1/health" \
-H "apikey: YOUR_ANON_OR_PUBLISHABLE_KEY"
A 200 with a small JSON body means the project is up and the address is right. "Could not resolve host" means the address is wrong.
Cause 2: the project is paused
Supabase pauses Free plan projects that have too little database activity over 7 days. Its documentation says the owner gets a warning email about a week before and a second email when it happens. A paused project answers every request with Supabase's own status code 540 project paused, and depending on the response the browser may report it as a plain fetch failure. Logins break for everyone at once, which is the giveaway.
Open the Supabase dashboard, choose the organization, then the project, and click Resume project. Supabase says a project can be restored for up to a year after it was paused, with its data and settings. To stop it from happening again, either move the project to a paid plan, since paid projects are not paused for inactivity, or make sure the app gets real use during the week. A staging project nobody opens is the classic victim.
Cause 3: the user's browser or network blocks Supabase
If the app works for you and fails for a handful of users, the problem is almost always on their side. Ad blockers and privacy extensions sometimes block third party API hosts. Company firewalls, school networks, VPNs and DNS filters can block the supabase.co domain. Whole countries can be affected too: in February 2026 internet providers in India blocked supabase.co for about a week, and Supabase recommended alternative DNS, a VPN or a custom domain as workarounds.
Test it the way the user sees it: a private window with extensions turned off, then a phone on mobile data with Wi-Fi off. If both work, your app is fine. For a permanent fix, use Supabase's custom domain feature so the API runs on api.yourdomain.com, a host that filters and blockers have no reason to single out. It is a paid add-on, so it is worth it once real customers depend on the app. Handle the error in the UI either way, so users see a clear message instead of a dead button:
import { isAuthRetryableFetchError } from "@supabase/supabase-js";
const { error } = await supabase.auth.signInWithPassword({ email, password });
if (error) {
if (isAuthRetryableFetchError(error)) {
setMessage("We could not reach the server. Check your connection, turn off ad blockers or VPN, and try again.");
} else {
setMessage(error.message);
}
}
Cause 4: CORS on an Edge Function or your own API
Supabase's own Auth and Data APIs send CORS headers already, so if login works and only one feature fails, look at what that feature calls. The usual culprit is an Edge Function that does not answer the OPTIONS preflight, or that crashes and returns an error without CORS headers. The browser then hides the real error behind "blocked by CORS policy" and Failed to fetch. Every response from the function needs the headers, including errors:
const corsHeaders = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "authorization, x-client-info, apikey, content-type",
};
Deno.serve(async (req) => {
if (req.method === "OPTIONS") {
return new Response("ok", { headers: corsHeaders });
}
try {
// your logic
return new Response(JSON.stringify({ ok: true }), {
headers: { ...corsHeaders, "Content-Type": "application/json" },
});
} catch (e) {
return new Response(JSON.stringify({ error: String(e) }), {
status: 500,
headers: { ...corsHeaders, "Content-Type": "application/json" },
});
}
});
Check the function logs in the Supabase dashboard while you reproduce the error, since a crash shows up there even when the browser only says CORS. The Lovable Edge Function CORS guide covers this case in depth, including how to tell a crash from a real header problem.
Cause 5: the page cancels its own request
If the request shows (canceled), nothing is wrong with Supabase. Your page navigated or reloaded while the request was still running, and the browser aborted it. Two patterns cause most of these in generated code:
- A login form with no
preventDefault(). Pressing Enter submits the form the old way and reloads the page, which kills the fetch. - A redirect right after calling Supabase without waiting for it, for example
supabase.auth.signOut()followed bywindow.location.href = "/"on the next line.
async function onSubmit(e) {
e.preventDefault();
setLoading(true);
const { error } = await supabase.auth.signInWithPassword({ email, password });
setLoading(false);
if (error) return setMessage(error.message);
navigate("/dashboard");
}
Await every Supabase call before you navigate. Newer supabase-js versions log aborted session refreshes during page loads as warnings instead of errors, so if you see occasional Failed to fetch warnings only while users click between pages, that is expected and harmless.
Cause 6: Supabase answered with a server error
If the auth error has a status like 502, 503 or 504, the request did reach Supabase, and it could not complete it. Check status.supabase.com and the project's Reports page. An overloaded small compute instance, a slow trigger on auth.users, or a query that runs into a timeout can all cause it. If a signup fails with a 500, the Database error saving new user guide is the likely match.
Prevention
Keep the Supabase URL and key in one place per environment and check them whenever you create a preview, remix a project or move hosts. Add the startup guard above so a bad value fails the build check instead of production logins. Keep at least one real user path hitting a Free plan project every week, or put production on a paid plan. Give every Edge Function the CORS block from day one. And show a friendly network error in the UI, because some of your users will always be on a network that blocks something.
FAQ
What does AuthRetryableFetchError mean in Supabase?
It is the error supabase-js auth throws when the request never got a usable response: a network failure, a CORS block or an aborted request. In that case its status is 0. The same class is used with a status such as 502 or 503 when Supabase answered with a server error, which can be retried later.
Why does it work locally but fail on my deployed site?
Usually the deployed build has a different Supabase URL. Vite and Next.js copy public environment variables into the bundle at build time, so a missing or old value on Vercel or Netlify ships a broken address. Fix the variable on the host and redeploy.
Is Failed to fetch a wrong password or an RLS problem?
No. A wrong password returns an HTTP 400 with invalid login credentials, and row level security returns empty data or a 401 or 403. Failed to fetch means the browser did not get an answer it could read, so the problem is the address, the network, CORS or a cancelled request.
Why do only some of my users see Failed to fetch?
When the app works for you and fails for a few users, it is nearly always their network or browser: an ad blocker or privacy extension, a company firewall, a school or ISP DNS filter, or a VPN. Ask them to try mobile data. A custom domain for your Supabase project avoids most of these blocks.
Does Safari show a different message?
Yes. Chrome says TypeError: Failed to fetch, Safari says Load failed, and Firefox says NetworkError when attempting to fetch resource. They are the same failure and the same checks apply.
Related guides
- Lovable + Supabase Edge Function CORS error: why the browser says failed to fetch
- Bolt.new works in preview but breaks on Netlify: missing environment variables
- Supabase login redirects to localhost (or the preview URL) after deploy: how to fix it
- Supabase auth email not sending in a Lovable app: the SMTP setup that actually works
- Supabase signUp fails with "Database error saving new user": fix the auth.users trigger