LeCroissant
05/16/2022, 2:07 PMburggraf
05/16/2022, 2:17 PMburggraf
05/16/2022, 2:23 PMLeCroissant
05/16/2022, 2:25 PMburggraf
05/16/2022, 2:26 PMLeCroissant
05/16/2022, 2:37 PMburggraf
05/16/2022, 2:46 PMburggraf
05/16/2022, 2:49 PM-- Gets some custom claim from the request JWT
create or replace function auth.someclaim() returns uuid as $$
select nullif(current_setting('request.jwt.claim.someclaim', true), '')::uuid;
$$ language sql stable;
but the jwt is passed as part of the http requestLeCroissant
05/16/2022, 3:18 PMburggraf
05/16/2022, 3:18 PMburggraf
05/16/2022, 3:19 PMLeCroissant
05/16/2022, 3:51 PMburggraf
05/16/2022, 3:54 PMburggraf
05/16/2022, 3:55 PMLeCroissant
05/16/2022, 4:19 PMLeCroissant
05/16/2022, 4:20 PMburggraf
05/16/2022, 4:59 PMburggraf
05/16/2022, 9:06 PMapp_metadata
. You would need a function to write this data to the user's record (and it would require the service token, since it's a server process). https://supabase.com/docs/reference/javascript/auth-api-updateuserbyid#updates-a-users-app_metadataburggraf
05/16/2022, 9:07 PMauth.users->'app_metadata'
burggraf
05/16/2022, 9:08 PMCREATE OR REPLACE FUNCTION get_my_claims() RETURNS "jsonb"
LANGUAGE "sql" STABLE
AS $$
select
coalesce(nullif(current_setting('request.jwt.claims', true), '')::jsonb -> 'app_metadata', '{}'::jsonb)::jsonb
$$;
burggraf
05/20/2022, 9:18 PM