Cannot access new service role API key from Edge Function runtime
edge functions
Hi,
so, apparently Supabase has deprecated their bad authentication scheme in favor of an even more broken one, while addressing none of the issues with the old one, and not even bumping the major version number to announce the breaking change. Cool - that's the quality I'm used to at this point.
One particular pain point with the newly introduced API keys, though, is that I have a bunch of Edge Functions which I only want to be accessible to users that know the service role key. The reasoning is that these Edge Functions perform system maintenance or data import tasks that regular users should not be able to control, and they only get called via an admin
curl
curl
ing them.
My previous solution essentially was this:
Deno.serve(async (req) => { if ( req.headers.get('authorization') !== `Bearer ${Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')}` ) { return new Response('Unauthorized', { status: 401 }); }
Deno.serve(async (req) => { if ( req.headers.get('authorization') !== `Bearer ${Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')}` ) { return new Response('Unauthorized', { status: 401 }); }
This worked perfectly fine for me. But with the new system, I am not sure what I'm supposed to do here.
1. I'm not supposed to use the JWT-based service role anymore. In local development, this already doesn't work, as the CLI tools no longer show it. (I could probably hack around that, but that wouldn't be future-proof.) 2. I can't use the new API key, as I am not sure how to access it. It doesn't appear to be documented anywhere how that key could be obtained, and in any case, it's not in
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.