postgrest-docs icon indicating copy to clipboard operation
postgrest-docs copied to clipboard

ERROR: type "basic_auth.jwt_token" does not exist

Open whatsdis opened this issue 6 years ago • 1 comments

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 avatar Nov 16 '19 07:11 whatsdis

@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.

steve-chavez avatar Nov 16 '19 14:11 steve-chavez