postgrest-docs
postgrest-docs copied to clipboard
ERROR: type "basic_auth.jwt_token" does not exist
hi I am following the guide at http://postgrest.org/en/stable/auth.html
and in this function I cannot execute it due to ERROR: type "basic_auth.jwt_token" does not exist
-- login should be on your exposed schema
create or replace function
login(email text, pass text) returns basic_auth.jwt_token as $$
declare
_role name;
result basic_auth.jwt_token;
begin
-- check email and password
select basic_auth.user_role(email, pass) into _role;
if _role is null then
raise invalid_password using message = 'invalid user or password';
end if;
select sign(
row_to_json(r), 'reallyreallyreallyreallyverysafe'
) as token
from (
select _role as role, login.email as email,
extract(epoch from now())::integer + 60*60 as exp
) r
into result;
return result;
end;
$$ language plpgsql security definer;
@whatsdis Hey there. To fix the error, you can create jwt_token like:
CREATE TYPE basic_auth.jwt_token AS (
token text
);
You could make a PR with this correction if you'd like to help the docs.