zf

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

commit 7c421718bb5178aae119949362a6541300d88e1b
parent a5b603553823d9be8c23c032fb07dc67f56af1a9
Author: srfsh <dev@srf.sh>
Date:   Thu, 15 Sep 2022 12:41:30 +0300

Zenflows.GQL.MW.Sign: reflect changes to Restroom and improve error messages

It now tells what happens.  Also, dumps the logs from Restroom if it fails.

It was requested by Puria and Alberto.

Diffstat:
Msrc/zenflows/gql/mw/sign.ex | 25++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/src/zenflows/gql/mw/sign.ex b/src/zenflows/gql/mw/sign.ex @@ -28,15 +28,30 @@ alias Zenflows.VF.Person @impl true def call(res, _opts) do if res.context.authenticate_calls? do - with %{gql_user: user, gql_sign: sign, gql_body: body} <- res.context, - {:ok, per} <- Person.Domain.one(user: user), - true <- Restroom.verify_graphql?(body, sign, per.eddsa_public_key) do + with {:ok, username, sign, body} <- fetch_ctx(res), + {:ok, per} <- fetch_user(username), + :ok <- Restroom.verify_graphql(body, sign, per.eddsa_public_key) do put_in(res.context[:req_user], per) - else _ -> - Absinthe.Resolution.put_result(res, {:error, "you are not authenticated"}) + else x -> + Absinthe.Resolution.put_result(res, x) end else res end end + +defp fetch_ctx(res) do + case res.context do + %{gql_user: username, gql_sign: sign, gql_body: body} -> + {:ok, username, sign, body} + _ -> {:error, "some headers are missing"} + end +end + +defp fetch_user(username) do + case Person.Domain.one(user: username) do + {:ok, user} -> {:ok, user} + _ -> {:error, "user not found"} + end +end end