© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•2w ago•
12 replies
nehatkhan

how to add data in custom claims of jwt

auth
create or replace function public.custom_access_token_hook(event jsonb)
returns jsonb
language plpgsql
as $$
declare
claims jsonb;
v_user_id uuid;
v_persona text;
begin
-- 1. Extract existing JWT claims
claims := event->'claims';

-- 2. Extract authenticated user id
v_user_id := (claims->>'sub')::uuid;

-- 3. Fetch persona from your table
select persona
into v_persona
from public.club
where user_id = v_user_id
limit 1;

-- 4. Inject persona into JWT if it exists
if v_persona is not null then
claims := jsonb_set(
claims,
'{persona}',
to_jsonb(v_persona),
true
);
end if;

-- 5. Put updated claims back into event
event := jsonb_set(event, '{claims}', claims, true);

-- 6. Return modified event
return event;
end;
$$;

-- Allow auth system to see public schema
grant usage on schema public
to supabase_auth_admin;

-- Allow hook execution
grant execute
on function public.custom_access_token_hook(jsonb)
to supabase_auth_admin;

grant all
on table public.club
to supabase_auth_admin;


hey there how to get persona inside user_metadata instead of getting the value in access_tokens
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

Forcing JWT refresh after setting custom claims
SupabaseSSupabase / help-and-questions
4y ago
JWT custom claims: Am I making the right choice?
SupabaseSSupabase / help-and-questions
4w ago
Custom claims package
SupabaseSSupabase / help-and-questions
4y ago
Custom JWT
SupabaseSSupabase / help-and-questions
7mo ago