docs: Simplify auth examples with OUT parameter
The jwt_token type was not created consistently in all examples, which can be confusing when following those. To return an object with a single key named token, it's enough to have an OUT parameter to the function. Resolves https://github.com/PostgREST/postgrest-docs/issues/280
This commit is contained in:
committed by
Wolfgang Walther
parent
7c6c056e92
commit
9b1ff2235a
@@ -162,20 +162,15 @@ As described in :ref:`client_auth`, we'll create a JWT token inside our login fu
|
||||
|
||||
.. code-block:: postgres
|
||||
|
||||
CREATE TYPE basic_auth.jwt_token AS (
|
||||
token text
|
||||
);
|
||||
|
||||
-- if you are not using psql, you need to replace :DBNAME with the current database's name.
|
||||
ALTER DATABASE :DBNAME SET "app.jwt_secret" to 'reallyreallyreallyreallyverysafe';
|
||||
|
||||
|
||||
CREATE FUNCTION public.login(username text, password text) RETURNS basic_auth.jwt_token
|
||||
CREATE FUNCTION public.login(username text, password text, OUT token text)
|
||||
LANGUAGE plpgsql security definer
|
||||
AS $$
|
||||
DECLARE
|
||||
_role name;
|
||||
result basic_auth.jwt_token;
|
||||
BEGIN
|
||||
-- check email and password
|
||||
SELECT basic_auth.check_user_pass(username, password) INTO _role;
|
||||
@@ -190,8 +185,7 @@ As described in :ref:`client_auth`, we'll create a JWT token inside our login fu
|
||||
SELECT login.username as role,
|
||||
extract(epoch FROM now())::integer + 60*60 AS exp
|
||||
) r
|
||||
INTO result;
|
||||
RETURN result;
|
||||
INTO token;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user