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;
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;