Auth Hooks error

I can't figure out why this is failing with the following error:

https://example.com?error=server_error&error_description=500%3A+Error+invoking+access+token+hook.#error=server_error&error_description=500%253A+Error+invoking+access+token+hook.

Auth hook function:

create or replace function public.profiles_auth_hook(event jsonb)
returns jsonb
language plpgsql
as $$
declare
  claims jsonb;
  profile_id profiles.id%type;
begin
  claims := event->'claims';
  -- Check if 'user_metadata' exists in claims
  if jsonb_typeof(claims->'user_metadata') is null then
    -- If 'user_metadata' does not exist, create an empty object
    claims := jsonb_set(claims, '{user_metadata}', '{}');
  end if;
  -- get user
  select id into profile_id from profiles where profiles.user_id = (event->>'user_id')::uuid and profiles.disabled = false limit 1;
  claims := jsonb_set(claims, '{user_metadata,pid}', to_jsonb(profile_id::text));
  return jsonb_set(event, '{claims}', claims);
end;
$$;
grant execute on function public.profiles_auth_hook to supabase_auth_admin;
revoke execute on function public.profiles_auth_hook from authenticated, anon;


Also, there is no documentation nor examples explaining how to use the new created claim in RLS policies.
Was this page helpful?