zf

zenflows testing
git clone https://s.sonu.ch/~srfsh/zf.git
Log | Files | Refs | Submodules | README | LICENSE

commit 945a2c0cac842c240ac2f967210bc4b4489a09e5
parent 1d6c3bd68689902dca99efebc417d6691f2a52b7
Author: srfsh <dev@srf.sh>
Date:   Tue, 26 Jul 2022 16:30:35 +0300

Zenflows.GQL.Schema: add only_guest? case

This allows some calls to be used without any sort of authentication.

Diffstat:
Msrc/zenflows/gql/schema.ex | 18++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/zenflows/gql/schema.ex b/src/zenflows/gql/schema.ex @@ -168,10 +168,20 @@ require Logger @impl true def middleware(mw, field, %{identifier: id}) when id in ~w[query mutation subscription]a do - if Absinthe.Type.meta(field, :only_admin?) do - [MW.Admin | mw] ++ [MW.Errors] - else - [MW.Sign | mw] ++ [MW.Errors] + alias Absinthe.Type + + cond do + # require nothing to be provided + Type.meta(field, :only_guest?) -> + mw ++ [MW.Errors] + + # require the admin key to be provided + Type.meta(field, :only_admin?) -> + [MW.Admin | mw] ++ [MW.Errors] + + # require every call to be signed + true -> + [MW.Sign | mw] ++ [MW.Errors] end end def middleware(mw, _, _), do: mw