© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•3y ago•
2 replies
Kevin Wolf

service_role key not working locally on rpc call

I created a custom function to get a user by its id:

CREATE OR REPLACE FUNCTION public.get_user_id_by_email(user_email text)
 RETURNS uuid
 LANGUAGE plpgsql
AS $function$
declare
  user_id uuid;
begin
  select id 
  from auth.users 
  where email = user_email 
  into user_id;

  return user_id;
end;
$function$
;
CREATE OR REPLACE FUNCTION public.get_user_id_by_email(user_email text)
 RETURNS uuid
 LANGUAGE plpgsql
AS $function$
declare
  user_id uuid;
begin
  select id 
  from auth.users 
  where email = user_email 
  into user_id;

  return user_id;
end;
$function$
;


However, when trying to execute it using the RPC function I got the following error:

{
  code: '42501',
  details: null,
  hint: null,
  message: 'permission denied for table users'
}
{
  code: '42501',
  details: null,
  hint: null,
  message: 'permission denied for table users'
}


Note: I double-checked that I am using the right service_role key by calling any of the
auth.admin
auth.admin
methods and it worked.
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

SUPABASE_SERVICE_ROLE_KEY is reset locally on "supabase functions serve"
SupabaseSSupabase / help-and-questions
2w ago
JWT Service Role Key
SupabaseSSupabase / help-and-questions
3d ago
understanding service_role key
SupabaseSSupabase / help-and-questions
3y ago
Hiding Service Role Key
SupabaseSSupabase / help-and-questions
4y ago