Custom claims hooks refuses to work
create or replace function public.custom_access_token_hook(event jsonb)
returns jsonb
language plpgsql
as $$
declare
original_claims jsonb;
new_claims jsonb;
claim text;
app_metadata jsonb;
begin
original_claims = event->'claims';
new_claims = '{}'::jsonb;
foreach claim in array array[
-- add claims you want to keep here
'iss',
'aud',
'exp',
'iat',
'sub',
'role',
'aal',
'session_id',
'jti', 'nbf', 'app_metadata', 'user_metadata', 'amr', 'email', 'phone','is_anonymous'
] loop
if original_claims ? claim then
-- For app_metadata, modify it before setting
if claim = 'app_metadata' then
app_metadata = original_claims->'app_metadata';
app_metadata = jsonb_set(app_metadata, '{test}', '"test"');
new_claims = jsonb_set(new_claims, array[claim], app_metadata);
else
-- For other claims, set them as before
new_claims = jsonb_set(new_claims, array[claim], original_claims->claim);
end if;
end if;
end loop;
raise log 'new_claims: %', new_claims;
return jsonb_build_object('claims', new_claims);
end
$$;
this hook does not work, the test: test does not show up in the jwt like it does in the logs... what is the reason for this?
this is what the log spits out "app_metadata": {
"test": "test",
"provider": "email",
"providers": [
"email"
]
},
returns jsonb
language plpgsql
as $$
declare
original_claims jsonb;
new_claims jsonb;
claim text;
app_metadata jsonb;
begin
original_claims = event->'claims';
new_claims = '{}'::jsonb;
foreach claim in array array[
-- add claims you want to keep here
'iss',
'aud',
'exp',
'iat',
'sub',
'role',
'aal',
'session_id',
'jti', 'nbf', 'app_metadata', 'user_metadata', 'amr', 'email', 'phone','is_anonymous'
] loop
if original_claims ? claim then
-- For app_metadata, modify it before setting
if claim = 'app_metadata' then
app_metadata = original_claims->'app_metadata';
app_metadata = jsonb_set(app_metadata, '{test}', '"test"');
new_claims = jsonb_set(new_claims, array[claim], app_metadata);
else
-- For other claims, set them as before
new_claims = jsonb_set(new_claims, array[claim], original_claims->claim);
end if;
end if;
end loop;
raise log 'new_claims: %', new_claims;
return jsonb_build_object('claims', new_claims);
end
$$;
this hook does not work, the test: test does not show up in the jwt like it does in the logs... what is the reason for this?
this is what the log spits out "app_metadata": {
"test": "test",
"provider": "email",
"providers": [
"email"
]
},