-- pgBouncer auth function
CREATE OR REPLACE FUNCTION public.get_auth(p_usename TEXT) RETURNS TABLE(username TEXT, password TEXT) AS
$$
BEGIN
    RAISE WARNING 'get_auth() called for user: %', p_usename;
    RETURN QUERY
    SELECT usename::TEXT, passwd::TEXT FROM pg_catalog.pg_shadow
    WHERE usename = p_usename;
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;

REVOKE ALL ON FUNCTION public.get_auth(p_usename TEXT) FROM PUBLIC;
GRANT EXECUTE ON FUNCTION public.get_auth(p_usename TEXT) TO pgbouncer;
