[Edge Functions] Invoking any Edge Function fails with 401 Unauthorized despite using valid service_role key #36548
Replies: 3 comments 3 replies
|
I've had this problem but don't quite remember how I solved this and couldn't recreate it To test if the function even runs i tried toggling off the JWT (its in |
|
Hey guys I figured it out , your Bearer in your request header is supposed to be your supabase anon key, you can find your supabase anon key localy by just creating a function like |
|
The service role key gives database privileges inside your code, but it does not automatically bypass Edge Function JWT verification at the gateway. If the function has JWT verification enabled, the request still needs an Authorization: Bearer ... header before your function runs. For a public test function, set verify_jwt = false under that function in supabase/config.toml, redeploy, then use the service role key only inside server-side code or secrets. Do not expose the service role key from a browser/client. |




Uh oh!
There was an error while loading. Please reload this page.
Hi everyone,
I'm pretty new to Supabase and have been trying to get Edge Functions to work, but I've run into a problem that I just can't seem to solve, and I would be so grateful for any help!
The Problem I'm Seeing:
No matter what I try, whenever I try to call my Edge Function, I get a 401 Unauthorized error that says {"error":{"message":"No auth credentials found","code":401}}.
This happens even when I try to use the service_role key, which I thought was supposed to have full access.
Here’s what I tried to do to make it as simple as possible:
I created a very basic "hello world" function just to test things out. Here is the code for it:
File: supabase/functions/hello-test/index.ts
Code:
TypeScript
import { serve } from "https://deno.land/std@0.177.0/http/server.ts"
serve(req => {
return new Response("Hello from my test function!", {
headers: { "Content-Type": "application/json" },
})
})
I deployed it using the CLI, which seemed to work fine.
Then I tried to call it from my terminal using this cURL command (with my actual service_role key put in place of the placeholder):
Bash
curl -i -X POST
-H "Authorization: Bearer YOUR_SERVICE_ROLE_KEY"
-H "apikey: YOUR_SERVICE_ROLE_KEY"
https://.supabase.co/functions/v1/hello-test
What I expected to happen:
I was hoping to see the "Hello from my test function!" message.
What actually happened:
Instead, I got the 401 Unauthorized error message. It feels like the function isn't even running, and the request is getting blocked before it gets there.
I've been trying to debug this for a while and have confirmed my keys and project URL are copied correctly. I'm really stuck and feel like I might be missing something simple.
Has anyone seen this kind of issue before? Any advice or suggestions would be amazing!
Thank you so much in advance.
All reactions