Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: revert changes to auth functions #1633

Closed
wants to merge 4 commits into from
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions migrations/20240624145325_recreate_auth_functions.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
-- set the search_path to an empty string to force fully qualified names in the function
do $$
begin
-- auth.uid() function
create or replace function {{ index .Options "Namespace" }}.uid()
returns uuid
set search_path to ''
as $func$
select
coalesce(
nullif(current_setting('request.jwt.claim.sub', true), ''),
(nullif(current_setting('request.jwt.claims', true), '')::jsonb ->> 'sub')
)::uuid
$func$ language sql stable;

-- auth.role() function
create or replace function {{ index .Options "Namespace" }}.role()
returns text
set search_path to ''
as $func$
select
coalesce(
nullif(current_setting('request.jwt.claim.role', true), ''),
(nullif(current_setting('request.jwt.claims', true), '')::jsonb ->> 'role')
)::text
$func$ language sql stable;

-- auth.email() function
create or replace function {{ index .Options "Namespace" }}.email()
returns text
set search_path to ''
as $func$
select
coalesce(
nullif(current_setting('request.jwt.claim.email', true), ''),
(nullif(current_setting('request.jwt.claims', true), '')::jsonb ->> 'email')
)::text
$func$ language sql stable;

-- auth.jwt() function
create or replace function {{ index .Options "Namespace" }}.jwt()
returns jsonb
as $func$
select
coalesce(
nullif(current_setting('request.jwt.claim', true), ''),
nullif(current_setting('request.jwt.claims', true), '')
Comment on lines +47 to +48
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm is it like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you referring to the lack of search_path ? Set that to '' the rest should be accurate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not actually sure that we need to replace .jwt() at all let me check.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry just wanted to validate this...

create or replace function {{ index .Options "Namespace" }}.jwt()

)::jsonb
$func$ language sql stable;
end $$;
Loading