I got 'TypeError: fetch failed'
const supabaseAdmin = createClient(
supabaseUrl,
supabaseServiceKey,
{
auth: {
persistSession: false,
autoRefreshToken: false,
},
}
);
const { data: testConnection, error: connectionError } = await supabaseAdmin
.from('users')
.select('id')
.limit(1);
if (connectionError) {
console.error('Supabase connection error:', connectionError);
return NextResponse.json(
{ error: 'Database connection failed. Please ensure Supabase is running.' },
{ status: 503 }
);
}
This is my code.
but when I try to run this, I got the error.
How can I fix this problem?
Any help is thanks.
thanks.
30 Replies
That is a pretty generic error usually meaning the fetch never made it to Supabase.
Check your dashboard API Gateway log to see if there.
Otherwise you have to see if it even makes a network call from your code and if so check the URL.
Log out your SupabaseUrl to make sure correct.
Also you show a message about Database connection failed 503, is that supposed to be the error you are getting or something you made up to return for you API.
I defined 503 error.
@garyaustin
Sorry ping you.
Now, I am not sure what you mean.
I am getting this error still now.
Could you please help me one by one?
I gave you some things to check/provide so a user here might help.
Did you console.log your supabaseURL to Supabase right before you create the client? Did you try and look at the dev console from the browser (if that works for your environment as the call to SB might be from a server) for the network request? Are you sure the 503 is to Supabase and not your Next server code? Also is this for all Supabase calls or just this one?
What is the status of your project (main dashboard page for project)?
Did you console.log your supabaseURL to Supabase right before you create the client? Did you try and look at the dev console from the browser (if that works for your environment as the call to SB might be from a server) for the network request? Are you sure the 503 is to Supabase and not your Next server code? Also is this for all Supabase calls or just this one?
What is the status of your project (main dashboard page for project)?
Everything looks good.
I got this error when I try to send request.

using postman.
Could you please help me this?
What request did you make?
I made get_user_by_email function
Can you check the Postgres log for what is getting that error?
The error means the user calling something in the public schema does not have a grant on it. This could mean you or an AI if you use one changed the schema grants.
here?

"connection authenticated: user="supabase_admin" method=trust (/etc/postgresql/pg_hba.conf:85)"
Logs then Postgres
Then look for an ERROR message
Did you change grants on the public schema?
Do you use an AI that might have?
There is no error. 🙁

How long ago did you run the test?
You can look back further and you can filter on error up top.
The error message you got came from the DB so it will be there or you are looking at a different project.
In API Gateway, I saw this error.

Try to just select a table from postman
And you have not answered about grant changes.
sorry bro.
I am begginer.
Could you please explain about grant?
You could have run SQL to keep anon/authenticated users from running.
Something like
Something like
REVOKE ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA "public" FROM "anon";
would keep anon from using public functions with the type of error you are seeing.
Please try the table select from postman.
Also you need to double check the Postgres logs as they have to have a permission error in them.
There is some SQL to run that can fix grants, but sort of need to know if you purposely wanted/needed to remove them for some reason.
I found this error message in postgres log
You still have not answered on if you changed the grants accidentally or on purpose. For instance you might have removed anon from that function so it could not be called by anon.
I think I didn't delete it.
Where I can add this again?
So I'll give you some code. You really have not given me enough info (like running a select to see if it also fails) to know what grants were removed. This code in the SQL editor will restore public back to default grants.
Thanks, let me try.
Thank you very much.
This is working well.
After run this command, I can get successfully result.
You are so cool
Thanks
I got so many stress from this problem and used many times.
You solved only for a few mins without enough information.
Thanks.
If I have any problem again, can I ask you again?
I am very beginner, so there are some problems to use Supabase.
You should ask new questions each time. This is a user helping user forum and many users can help.
Thanks.
I like Supabase so much.
It is very useful.
Thanks again for your helping.
Also you need to be careful on how your grants got removed as if your AI is telling you do that, it might be for some security reason.
Yes
This code is wrong?
in Postman, I got perfect result.
But in my project, I got same issue again. 🙁
So sad
@garyaustin
Please help me again. 🙏🏽
@garyaustin
I am using Next.js
I don't know use next.js or react.
Did you check that DEFAULT_SUPABASE_URL is correct?
Otherwise you will need to debug your code.
With Postman working it is not your project generating the issue and there are no bugs with supabase-js like this.
With Postman working it is not your project generating the issue and there are no bugs with supabase-js like this.
Thanks.
You are right.
That's my fault.
I put wrong supabase_url
Thanks very much cool man.
:supabase:
Supabase is best